From d89d493141b146e72c9476f195eef36465ee541c Mon Sep 17 00:00:00 2001 From: Alex Opie Date: Fri, 24 Oct 2025 12:06:39 +1300 Subject: [PATCH] Unescape componentsFound.locationsFoundAt The use of the Uri class was mangling paths that include spaces. --- .../DefaultGraphTranslationService.cs | 1 + .../DefaultGraphTranslationServiceTests.cs | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Services/GraphTranslation/DefaultGraphTranslationService.cs b/src/Microsoft.ComponentDetection.Orchestrator/Services/GraphTranslation/DefaultGraphTranslationService.cs index 788b76181..e7009e8a9 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/Services/GraphTranslation/DefaultGraphTranslationService.cs +++ b/src/Microsoft.ComponentDetection.Orchestrator/Services/GraphTranslation/DefaultGraphTranslationService.cs @@ -295,6 +295,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 6979806f8..5b6dffae1 100644 --- a/test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DefaultGraphTranslationServiceTests.cs +++ b/test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DefaultGraphTranslationServiceTests.cs @@ -39,6 +39,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() {