diff --git a/docs/guides/managed/nuget-nupkg.md b/docs/guides/managed/nuget-nupkg.md
index c37712a139..1d0f166383 100644
--- a/docs/guides/managed/nuget-nupkg.md
+++ b/docs/guides/managed/nuget-nupkg.md
@@ -79,9 +79,11 @@ still succeeds with a limitation.
The `.nuspec` is chosen from a unique OPC relationship with Type
`http://schemas.microsoft.com/packaging/2010/07/manifest` when that target
-exists in the ZIP. Both `Relationships` and `Relationship` must use the OPC
-relationships namespace. The inspector skips other child elements and still
-considers eligible relationships beside them. Without an eligible target, it
+exists in the ZIP. `TargetMode` must be omitted or exactly `Internal` for
+the relationship to select a package member. Both `Relationships` and
+`Relationship` must use the OPC relationships namespace. The inspector skips
+other child elements and considers eligible relationships beside them.
+Without an eligible target, it
uses a unique `.nuspec` at the package root. Multiple conflicting manifests
are not decoded.
diff --git a/src/nuget/NugetNupkgParser.test.ts b/src/nuget/NugetNupkgParser.test.ts
index b7ab9a1e00..24a0071120 100644
--- a/src/nuget/NugetNupkgParser.test.ts
+++ b/src/nuget/NugetNupkgParser.test.ts
@@ -469,30 +469,46 @@ it("stops expanding an OPC relationships member at the budget when its declared
}
});
-it("leaves an external manifest relationship unfollowed even when it names a ZIP member", async () => {
- const bytes = await nugetNupkgFixture({
- includeRels: false,
- extraMembers: {
- "_rels/.rels": `
+it.each([
+ { mode: "External", selected: false, limitation: "is external" },
+ { mode: "Internal", selected: true, limitation: null },
+ { mode: "Unknown", selected: false, limitation: "has an invalid TargetMode" },
+ { mode: "", selected: false, limitation: "has an invalid TargetMode" },
+ {
+ mode: "internal",
+ selected: false,
+ limitation: "has an invalid TargetMode",
+ },
+])(
+ "uses the declared OPC manifest TargetMode $mode",
+ async ({ mode, selected, limitation }) => {
+ const bytes = await nugetNupkgFixture({
+ includeRels: false,
+ extraMembers: {
+ "_rels/.rels": `
-
+
`,
- "content/Other.nuspec": ungroupedNuspec,
- },
- });
- const report = nugetNupkgSchema.parse(
- await parseNugetNupkg(bytes, artifactOf(bytes), defaults),
- );
- expect(report.nuspec).toMatchObject({
- path: "Demo.Package.nuspec",
- source: "root-nuspec",
- });
- expect(report.identity?.id).toBe("Demo.Package");
- expect(report.limitations).toContain(
- 'OPC manifest relationship Target "content/Other.nuspec" is external and was not followed.',
- );
-});
+ "content/Other.nuspec": ungroupedNuspec,
+ },
+ });
+ const report = nugetNupkgSchema.parse(
+ await parseNugetNupkg(bytes, artifactOf(bytes), defaults),
+ );
+ expect(report.nuspec).toMatchObject({
+ path: selected ? "content/Other.nuspec" : "Demo.Package.nuspec",
+ source: selected ? "opc-relationship" : "root-nuspec",
+ });
+ expect(report.identity?.id).toBe(
+ selected ? "Ungrouped.Package" : "Demo.Package",
+ );
+ if (limitation !== null)
+ expect(report.limitations).toContain(
+ `OPC manifest relationship Target "content/Other.nuspec" ${limitation} and was not followed.`,
+ );
+ },
+);
const manifestRels = (target: string) => `
diff --git a/src/nuget/NugetNupkgParser.ts b/src/nuget/NugetNupkgParser.ts
index 7a02430514..2732e33716 100644
--- a/src/nuget/NugetNupkgParser.ts
+++ b/src/nuget/NugetNupkgParser.ts
@@ -294,13 +294,20 @@ const opcManifestTargets = (
const target = attribute(relationship, "Target");
if (target === null) continue;
const displayedTarget = redactRecordedTransportUrl(target).url;
- // OPC external targets may be relative, so the mode decides, not the URI shape.
- if (attribute(relationship, "TargetMode")?.toLowerCase() === "external") {
+ // Only an absent mode defaults to Internal. External targets can be relative.
+ const mode = relationship.getAttributeNS(null, "TargetMode");
+ if (mode === "External") {
limitations.push(
`OPC manifest relationship Target ${targetLabel(displayedTarget)} is external and was not followed.`,
);
continue;
}
+ if (mode !== null && mode !== "Internal") {
+ limitations.push(
+ `OPC manifest relationship Target ${targetLabel(displayedTarget)} has an invalid TargetMode and was not followed.`,
+ );
+ continue;
+ }
if (/^[a-z][a-z0-9+.-]*:/iu.test(target) || target.startsWith("//")) {
limitations.push(
`OPC manifest relationship Target ${targetLabel(displayedTarget)} has a URI scheme or authority and was not followed.`,