Skip to content

Commit 37f14a1

Browse files
Fix CargoComponent.PackageURL
1 parent a1025df commit 37f14a1

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Microsoft.ComponentDetection.Contracts/TypedComponent/CargoComponent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public CargoComponent(string name, string version, string author = null, string
3636

3737
public override ComponentType Type => ComponentType.Cargo;
3838

39-
public override PackageURL PackageUrl => new PackageURL("cargo", string.Empty, this.Name, this.Version, null, string.Empty);
39+
public override PackageURL PackageUrl => new PackageURL("cargo", null, this.Name, this.Version, null, null);
4040

4141
protected override string ComputeId() => $"{this.Name} {this.Version} - {this.Type}";
4242
}

test/Microsoft.ComponentDetection.Contracts.Tests/PurlGenerationTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,16 @@ public void CocoaPodNameShouldPurlWithCustomQualifier()
109109

110110
packageOne.PackageUrl.ToString().Should().Be("pkg:cocoapods/[email protected]?repository_url=https://custom_repo.example.com/path/to/repo/specs.git");
111111
}
112+
113+
[TestMethod]
114+
public void CargoShouldSupportPurl()
115+
{
116+
// https://github.com/package-url/purl-spec/blob/main/PURL-TYPES.rst#cargo
117+
var packageOne = new CargoComponent("rand", "0.7.2");
118+
var packageTwo = new CargoComponent("rand", "0.7.3", "RodneyRichardson", "MIT", "https://custom_repo.example.com/path/to/repo/specs.git");
119+
120+
packageOne.PackageUrl.Type.Should().Be("cargo");
121+
packageOne.PackageUrl.ToString().Should().Be("pkg:cargo/[email protected]");
122+
packageTwo.PackageUrl.ToString().Should().Be("pkg:cargo/[email protected]");
123+
}
112124
}

0 commit comments

Comments
 (0)