diff --git a/docs/guides/managed/nuget-nupkg.md b/docs/guides/managed/nuget-nupkg.md index 3105c502dc..217e52584a 100644 --- a/docs/guides/managed/nuget-nupkg.md +++ b/docs/guides/managed/nuget-nupkg.md @@ -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 diff --git a/docs/maven-gradle-metadata.md b/docs/maven-gradle-metadata.md index 7237fed2ed..b8c8ba7ff5 100644 --- a/docs/maven-gradle-metadata.md +++ b/docs/maven-gradle-metadata.md @@ -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). diff --git a/src/java/MavenGradleMetadataParser.test.ts b/src/java/MavenGradleMetadataParser.test.ts index d15c7ce8f2..c80a521830 100644 --- a/src/java/MavenGradleMetadataParser.test.ts +++ b/src/java/MavenGradleMetadataParser.test.ts @@ -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( + "\r\n 4.0.0\r\n demo\r\n \r\n first\r\nsecond\rthird\r\n \r\n\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(` com.example diff --git a/src/java/MavenGradleMetadataParser.ts b/src/java/MavenGradleMetadataParser.ts index c054819c35..1af50aaea7 100644 --- a/src/java/MavenGradleMetadataParser.ts +++ b/src/java/MavenGradleMetadataParser.ts @@ -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" diff --git a/src/nuget/NugetNupkgParser.test.ts b/src/nuget/NugetNupkgParser.test.ts index b1eec8da32..2431daaeeb 100644 --- a/src/nuget/NugetNupkgParser.test.ts +++ b/src/nuget/NugetNupkgParser.test.ts @@ -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>/u, + "First line.\r\nSecond line.\rThird line.", + ), + }); + 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) => { diff --git a/src/nuget/NugetNupkgParser.ts b/src/nuget/NugetNupkgParser.ts index 32a29bed0a..4f5262638c 100644 --- a/src/nuget/NugetNupkgParser.ts +++ b/src/nuget/NugetNupkgParser.ts @@ -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(