fix(artifacts): apply XML end-of-line handling to nuspec and POM text (#11846)

The .nuspec, its OPC relationships and the Maven POM now parse with
lineEndings normalize, as XML 1.0 section 2.11 and the NuGet and Maven
readers do. Text from CRLF files no longer keeps carriage returns.
This commit is contained in:
RRFZ authored and GitHub committed 2026-11-18 21:48:57 +08:00
1 parent da5ff5e7a7
commit 372e6e2fa0
6 files changed
+42 -5

No files matched your search

+3 -1
View File
@@ -29,7 +29,9 @@ requires an absolute filesystem path and preserves that exact selection:
The inline Evidence result contains the artifact path, SHA-256, and byte length.
`identity` reports `id`, `version`, `authors`, and `description` as present in
the `.nuspec` metadata. Missing fields are `null`. When no `.nuspec` can be
the `.nuspec` metadata. Missing fields are `null`. The `.nuspec` and OPC
relationships go through XML end-of-line handling, as NuGet's reader applies
it: CRLF and lone CR read as LF. When no `.nuspec` can be
selected, `identity` is `null`.
`license` reports the `.nuspec` license element: `type` is `expression` or
+2 -1
View File
@@ -35,7 +35,8 @@ selected default remains recorded.
`coordinates` holds `group_id`, `artifact_id`, `version`, and `packaging` as
spelled. Missing project coordinates stay `null`. A `${property}` spelling is
kept as written and listed in `unresolved`; this reader does not interpolate
properties or inherit parent or BOM values.
properties or inherit parent or BOM values. POM text goes through XML
end-of-line handling, as Maven's reader applies it: CRLF and lone CR read as LF.
When a parent is declared, omitted project group/version fields point to the
parent as possible sources. An omitted project `artifactId` is a missing child
coordinate: [only group/version coordinates may be inherited](https://maven.apache.org/pom.html#Maven_Coordinates).
@@ -415,6 +415,19 @@ it("removes credentials from POM property values", () => {
expect(JSON.stringify(report)).not.toContain("password");
});
it("applies XML end-of-line handling to POM text", () => {
const report = parse(
"<project>\r\n <modelVersion>4.0.0</modelVersion>\r\n <artifactId>demo</artifactId>\r\n <properties>\r\n <banner>first\r\nsecond\rthird</banner>\r\n </properties>\r\n</project>\r\n",
);
expect(report.properties).toEqual([
{
name: "banner",
value: "first\nsecond\nthird",
value_credentials_redacted: false,
},
]);
});
it("lists properties in packaging, scope, type and classifier", () => {
const report = parse(`<project>
<groupId>com.example</groupId>
+3 -1
View File
@@ -272,9 +272,11 @@ const parsePom = (
MAVEN_GRADLE_METADATA_XML_NODES,
nodes,
);
// Maven's XML reader applies XML 1.0 end-of-line handling, so a POM saved
// with CRLF yields the same property and coordinate text as one with LF.
const parsed = parseXmlDocument(xml, {
doctype: "reject",
lineEndings: "preserve",
lineEndings: "normalize",
});
if (!parsed.ok)
throw parsed.error.kind === "unsupported"
+17
View File
@@ -525,6 +525,23 @@ it("reads manifest text written as CDATA and as mixed text and CDATA", async ()
});
});
it("applies XML end-of-line handling to manifest text", async () => {
const bytes = await nugetNupkgFixture({
nuspec: ungroupedNuspec
.replaceAll("\n", "\r\n")
.replace(
/<description>[^<]*<\/description>/u,
"<description>First line.\r\nSecond line.\rThird line.</description>",
),
});
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(bytes, artifactOf(bytes), defaults),
);
expect(report.identity?.description).toBe(
"First line.\nSecond line.\nThird line.",
);
});
it.for(["constructor/file.txt", "__proto__/file.txt", "toString/file.txt"])(
"keeps payload folder %s at the unknown role",
async (name) => {
+4 -2
View File
@@ -220,7 +220,7 @@ const opcManifestTargets = (
): OpcManifestTarget[] => {
const parsed = parseXmlDocument(xml, {
doctype: "reject",
lineEndings: "preserve",
lineEndings: "normalize",
});
if (!parsed.ok) {
limitations.push(
@@ -336,9 +336,11 @@ const parseNuspecDocument = (
repository: null,
dependency_groups: [],
};
// NuGet reads the .nuspec with XDocument, which applies XML 1.0 end-of-line
// handling, so a description packed with CRLF reads with LF line breaks.
const parsed = parseXmlDocument(xml, {
doctype: "reject",
lineEndings: "preserve",
lineEndings: "normalize",
});
if (!parsed.ok) {
limitations.push(