Skip to content

Commit 7dde1e2

Browse files
authored
Merge pull request #137 from lxop/unescape-locationsfoundat
Unescape the locationsFoundAt paths
2 parents 333866a + 9b429e3 commit 7dde1e2

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

componentDetection.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,44 @@ describe("ComponentDetection.processComponentsToManifests", () => {
156156
expect(manifests[0].indirectDependencies()).toHaveLength(1);
157157
expect(manifests[0].countDependencies()).toBe(1);
158158
});
159+
160+
test("un-escapes URL-encoded locationsFoundAt", () => {
161+
const componentsFound = [
162+
{
163+
component: {
164+
name: "test-package",
165+
version: "1.0.0",
166+
packageUrl: {
167+
Scheme: "pkg",
168+
Type: "nuget",
169+
Name: "test-package",
170+
Version: "1.0.0"
171+
},
172+
id: "test-package 1.0.0 - nuget"
173+
},
174+
isDevelopmentDependency: false,
175+
topLevelReferrers: [], // Empty = direct dependency
176+
locationsFoundAt: ["/my%20project/my%20project.csproj"]
177+
}
178+
];
179+
180+
const dependencyGraphs: DependencyGraphs = {
181+
"my project/my project.csproj": {
182+
graph: { "test-package": null },
183+
explicitlyReferencedComponentIds: ["test-package 1.0.0 - nuget"],
184+
developmentDependencies: [],
185+
dependencies: []
186+
}
187+
};
188+
189+
const manifests = ComponentDetection.processComponentsToManifests(componentsFound, dependencyGraphs);
190+
191+
expect(manifests).toHaveLength(1);
192+
expect(manifests[0].name).toBe("my project/my project.csproj");
193+
expect(manifests[0].directDependencies()).toHaveLength(1);
194+
expect(manifests[0].indirectDependencies()).toHaveLength(0);
195+
expect(manifests[0].countDependencies()).toBe(1);
196+
});
159197
});
160198

161199
describe('normalizeDependencyGraphPaths', () => {

componentDetection.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ export default class ComponentDetection {
154154
packages.forEach((pkg: ComponentDetectionPackage) => {
155155
pkg.locationsFoundAt.forEach((location: any) => {
156156
// Use the normalized path (remove leading slash if present)
157-
const normalizedLocation = location.startsWith('/') ? location.substring(1) : location;
157+
let normalizedLocation = location.startsWith('/') ? location.substring(1) : location;
158+
// Unescape the path, as upstream ComponentDetection emits locationsFoundAt in URL-encoded form
159+
normalizedLocation = decodeURIComponent(normalizedLocation);
158160

159161
if (!manifests.find((manifest: Manifest) => manifest.name == normalizedLocation)) {
160162
const manifest = new Manifest(normalizedLocation, normalizedLocation);

dist/index.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)