summaryrefslogtreecommitdiff
path: root/cli/npm
diff options
context:
space:
mode:
authorMarvin Hagemeister <marvin@deno.com>2024-10-18 20:38:57 +0200
committerGitHub <noreply@github.com>2024-10-18 20:38:57 +0200
commit4b99cde504854baabdcf912f2fce3a7448119653 (patch)
tree2bb5696a8300d2113553706eea0824a50f51b015 /cli/npm
parent1bccf45ecb8b5ce2aa685d650c6654bf6c25e605 (diff)
fix(npm): ensure scoped package name is encoded in URLs (#26390)
Fixes https://github.com/denoland/deno/issues/26385
Diffstat (limited to 'cli/npm')
-rw-r--r--cli/npm/managed/cache/registry_info.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/cli/npm/managed/cache/registry_info.rs b/cli/npm/managed/cache/registry_info.rs
index 597a2283f..6c4a7503b 100644
--- a/cli/npm/managed/cache/registry_info.rs
+++ b/cli/npm/managed/cache/registry_info.rs
@@ -242,6 +242,14 @@ impl RegistryInfoDownloader {
fn get_package_url(&self, name: &str) -> Url {
let registry_url = self.npmrc.get_registry_url(name);
+ // The '/' character in scoped package names "@scope/name" must be
+ // encoded for older third party registries. Newer registries and
+ // npm itself support both ways
+ // - encoded: https://registry.npmjs.org/@rollup%2fplugin-json
+ // - non-ecoded: https://registry.npmjs.org/@rollup/plugin-json
+ // To support as many third party registries as possible we'll
+ // always encode the '/' character.
+
// list of all characters used in npm packages:
// !, ', (, ), *, -, ., /, [0-9], @, [A-Za-z], _, ~
const ASCII_SET: percent_encoding::AsciiSet =
@@ -253,11 +261,14 @@ impl RegistryInfoDownloader {
.remove(b'*')
.remove(b'-')
.remove(b'.')
- .remove(b'/')
.remove(b'@')
.remove(b'_')
.remove(b'~');
let name = percent_encoding::utf8_percent_encode(name, &ASCII_SET);
- registry_url.join(&name.to_string()).unwrap()
+ registry_url
+ // Ensure that scoped package name percent encoding is lower cased
+ // to match npm.
+ .join(&name.to_string().replace("%2F", "%2f"))
+ .unwrap()
}
}