diff --git a/scripts/__tests__/public-install-registry.test.mjs b/scripts/__tests__/public-install-registry.test.mjs index 1edd1ff7573..a175a8274fe 100644 --- a/scripts/__tests__/public-install-registry.test.mjs +++ b/scripts/__tests__/public-install-registry.test.mjs @@ -124,7 +124,9 @@ test('the registry exposes only known tarballs, redirects other packages to npm assert.equal(await (await fetch(metadata.versions['1.0.0'].dist.tarball)).text(), 'packed bytes'); const external = await fetch(`${registry.url}/@other%2fpkg`, { redirect: 'manual' }); assert.equal(external.status, 302); - assert.equal(external.headers.get('location'), 'https://registry.npmjs.org/%40other%2Fpkg'); + assert.equal(external.headers.get('location'), 'https://registry.npmjs.org/@other%2fpkg'); + const unscoped = await fetch(`${registry.url}/other-pkg`, { redirect: 'manual' }); + assert.equal(unscoped.headers.get('location'), 'https://registry.npmjs.org/other-pkg'); assert.equal((await fetch(`${registry.url}/-/900.tgz`)).status, 404); assert.equal((await fetch(`${registry.url}/some%2foutside%2ffile`)).status, 404); assert.equal((await fetch(`${registry.url}/@ci%2fpkg`, { method: 'POST' })).status, 405); diff --git a/scripts/public-install-registry.mjs b/scripts/public-install-registry.mjs index b0b6d80c994..06a23b64683 100644 --- a/scripts/public-install-registry.mjs +++ b/scripts/public-install-registry.mjs @@ -54,7 +54,7 @@ export async function startPackedRegistry(directory) { if (!packageName.test(path)) { response.writeHead(404).end(); return; } const entry = packages.get(path); if (!entry) { - response.writeHead(302, { location: `https://registry.npmjs.org/${encodeURIComponent(path)}` }).end(); + response.writeHead(302, { location: `https://registry.npmjs.org/${path.replace('/', '%2f')}` }).end(); return; } const { manifest, integrity } = entry;