diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Services/GraphTranslation/DefaultGraphTranslationService.cs b/src/Microsoft.ComponentDetection.Orchestrator/Services/GraphTranslation/DefaultGraphTranslationService.cs index 179c9303d..e00f1b578 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/Services/GraphTranslation/DefaultGraphTranslationService.cs +++ b/src/Microsoft.ComponentDetection.Orchestrator/Services/GraphTranslation/DefaultGraphTranslationService.cs @@ -296,6 +296,7 @@ private HashSet MakeFilePathsRelative(ILogger logger, DirectoryInfo root relativePath = "/" + relativePath; } + relativePath = Uri.UnescapeDataString(relativePath); relativePathSet.Add(relativePath); } diff --git a/test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DefaultGraphTranslationServiceTests.cs b/test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DefaultGraphTranslationServiceTests.cs index fee4229c7..b2716196c 100644 --- a/test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DefaultGraphTranslationServiceTests.cs +++ b/test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DefaultGraphTranslationServiceTests.cs @@ -40,6 +40,41 @@ public DefaultGraphTranslationServiceTests() this.sourceDirectory.Create(); } + [TestMethod] + public void UnescapeComponentLocations() + { + // Arrange + var projectPath = "/my project/my project.csproj"; + + var singleFileComponentRecorder = this.componentRecorder.CreateSingleFileComponentRecorder(Path.Join(this.sourceDirectory.FullName, projectPath)); + var processingResult = new DetectorProcessingResult + { + ResultCode = ProcessingResultCode.Success, + ContainersDetailsMap = new Dictionary + { + { + this.sampleContainerDetails.Id, this.sampleContainerDetails + }, + }, + ComponentRecorders = [(this.componentDetectorMock.Object, this.componentRecorder)], + }; + + var detectedComponent = new DetectedComponent(new NuGetComponent("nugetComponent", "4.5.6")); + singleFileComponentRecorder.RegisterUsage(detectedComponent); + + var settings = new ScanSettings { SourceDirectory = this.sourceDirectory }; + + // Act + var result = this.serviceUnderTest.GenerateScanResultFromProcessingResult(processingResult, settings); + + // Assert + result.Should().NotBeNull(); + result.ComponentsFound.Should().ContainSingle(); + + var resultComponent = result.ComponentsFound.Single(); + resultComponent.LocationsFoundAt.Should().BeEquivalentTo([projectPath]); + } + [TestMethod] public void GenerateScanResultFromResult_WithCustomLocations() {