Skip to content

Commit 37b76b6

Browse files
committed
Add regression test
1 parent 23f7205 commit 37b76b6

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

test/Microsoft.ComponentDetection.Detectors.Tests/VcpkgComponentDetectorTests.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,59 @@ public async Task TestTinyxmlAndResourceAsync()
150150
sbomComponent.DownloadLocation.Should().Be("git+https://github.com/leethomason/tinyxml2");
151151
}
152152

153+
[TestMethod]
154+
public async Task TestResourceWithSlashInNameProducesValidPackageUrlAsync()
155+
{
156+
var spdxFile = """
157+
{
158+
"SPDXID": "SPDXRef-DOCUMENT",
159+
"documentNamespace": "https://spdx.org/spdxdocs/brotli-x64-windows",
160+
"name": "brotli:x64-windows@1.0.9",
161+
"packages": [
162+
{
163+
"name": "brotli",
164+
"SPDXID": "SPDXRef-port",
165+
"versionInfo": "1.0.9#0",
166+
"downloadLocation": "git+https://github.com/Microsoft/vcpkg#ports/brotli",
167+
"licenseConcluded": "NOASSERTION",
168+
"licenseDeclared": "NOASSERTION",
169+
"copyrightText": "NOASSERTION"
170+
},
171+
{
172+
"SPDXID": "SPDXRef-resource-1",
173+
"name": "google/brotli",
174+
"downloadLocation": "git+https://github.com/google/brotli@1.0.9",
175+
"licenseConcluded": "NOASSERTION",
176+
"licenseDeclared": "NOASSERTION",
177+
"copyrightText": "NOASSERTION"
178+
}
179+
]
180+
}
181+
""";
182+
var (scanResult, componentRecorder) = await this
183+
.detectorTestUtility.WithFile("vcpkg.spdx.json", spdxFile)
184+
.ExecuteDetectorAsync();
185+
186+
scanResult.ResultCode.Should().Be(ProcessingResultCode.Success);
187+
188+
var detectedComponents = componentRecorder.GetDetectedComponents();
189+
var components = detectedComponents.ToList();
190+
191+
components.Should().HaveCount(2);
192+
193+
var resourceComponent = (VcpkgComponent)components
194+
.First(c => ((VcpkgComponent)c.Component).SPDXID == "SPDXRef-resource-1")
195+
.Component;
196+
resourceComponent.Name.Should().Be("google/brotli");
197+
resourceComponent.Version.Should().Be("1.0.9");
198+
199+
// This was the bug: names with slashes caused MalformedPackageUrlException
200+
var purl = resourceComponent.PackageUrl;
201+
purl.Should().NotBeNull();
202+
purl.ToString().Should().Contain("vcpkg");
203+
purl.ToString().Should().Contain("brotli");
204+
}
205+
153206
[TestMethod]
154207
public async Task TestBlankJsonAsync()
155208
{

0 commit comments

Comments
 (0)