Skip to content

Commit c8afb1c

Browse files
Merge pull request #8 from jonathansantilli/alert-autofix-4
Potential fix for code scanning alert no. 4: Incomplete string escaping or encoding
2 parents e98b73c + f214de4 commit c8afb1c

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/layer3-dynamic/resource-fetcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function defaultDeps(): ResourceFetcherDeps {
4848
function endpointFor(request: ResourceRequest): string {
4949
if (request.kind === "npm") {
5050
const pkg = request.locator.startsWith("@")
51-
? request.locator.replace("/", "%2f")
51+
? request.locator.replace(/\//g, "%2f")
5252
: request.locator;
5353
return `https://registry.npmjs.org/${pkg}`;
5454
}

tests/layer3/resource-fetcher.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@ describe("task 25 resource fetcher", () => {
3232
expect(fetch).toHaveBeenCalledTimes(1);
3333
});
3434

35+
it("encodes every slash in scoped npm locators before fetching registry metadata", async () => {
36+
const fetch = vi.fn(async () => {
37+
return new Response(JSON.stringify({ name: "@org/pkg", version: "1.0.0" }), {
38+
status: 200,
39+
headers: { "content-type": "application/json" },
40+
});
41+
});
42+
43+
await fetchResourceMetadata(
44+
{ id: "npm:@org/pkg/nested", kind: "npm", locator: "@org/pkg/nested" },
45+
depsWithFetch(fetch),
46+
);
47+
48+
expect(fetch).toHaveBeenCalledWith(
49+
"https://registry.npmjs.org/@org%2fpkg%2fnested",
50+
expect.any(Object),
51+
);
52+
});
53+
3554
it("returns auth_failure for 401/403 responses without retry loop", async () => {
3655
const fetch = vi.fn(async () => {
3756
return new Response("unauthorized", { status: 401 });

0 commit comments

Comments
 (0)