mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 13:12:26 +00:00
fix(artifacts): read Maven and Gradle metadata with a UTF-8 BOM (#12009)
Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com>
This commit is contained in:
1 parent
2f6773cbc7
commit
2aaf76c5c1
2 files changed
+32
-2
No files matched your search
@@ -1020,3 +1020,34 @@ it("refuses a POM past the XML node allowance before building its tree", () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
["gradle-module", gradleModuleFixture, "/artifacts/demo.module"],
|
||||
["maven-pom", mavenPomFixture, "/artifacts/pom.xml"],
|
||||
] as const)(
|
||||
"reads %s with a UTF-8 signature and retains the input identity",
|
||||
(format, source, path) => {
|
||||
const signed = "\ufeff" + source;
|
||||
const report = parse(signed, path);
|
||||
const original = parse(source, path);
|
||||
expect(report).toEqual({
|
||||
...original,
|
||||
artifact: {
|
||||
path,
|
||||
bytes: Buffer.byteLength(signed),
|
||||
sha256: createHash("sha256").update(signed, "utf8").digest("hex"),
|
||||
},
|
||||
coverage: {
|
||||
...original.coverage,
|
||||
examined_bytes: Buffer.byteLength(signed),
|
||||
},
|
||||
});
|
||||
expect(report.format).toBe(format);
|
||||
},
|
||||
);
|
||||
|
||||
it("still rejects duplicate fields after a Gradle UTF-8 signature", () => {
|
||||
expect(() =>
|
||||
parse('\ufeff{"formatVersion":"1.1","formatVersion":"1.1"}'),
|
||||
).toThrow(/declares a field more than once/u);
|
||||
});
|
||||
@@ -643,8 +643,7 @@ export const parseMavenGradleMetadata = (
|
||||
);
|
||||
let source: string;
|
||||
try {
|
||||
// ignoreBOM: true kept a leading U+FEFF; "preserve" is that same policy.
|
||||
source = decodeStrictUtf8(bytes, "preserve");
|
||||
source = decodeStrictUtf8(bytes, "strip-signature");
|
||||
} catch {
|
||||
throw malformedInput(
|
||||
MAVEN_GRADLE_METADATA_FORMAT,
|
||||
|
||||
Reference in new issue
Block a user