diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-06-15 20:36:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-15 18:36:33 +0000 |
commit | 0733943fe7de30fa54d6cd8ee34f7393e8bb7482 (patch) | |
tree | a4eab892bdc6c93b0e66590d619e172d2d2dcdbe /cli/npm/registry.rs | |
parent | fa63fd4610fbe4a1d95c4da776e4a1cfa8f8e0b9 (diff) |
fix(cli): avoid crash on import of invalid module names (#19523)
Fixes https://github.com/denoland/deno/issues/17748
Closes #17770
Co-authored-by: Anton Bershanskiy
<bershanskiy@users.noreply.github.com>
Co-authored-by: David Sherret <dsherret@users.noreply.github.com>
Diffstat (limited to 'cli/npm/registry.rs')
-rw-r--r-- | cli/npm/registry.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/cli/npm/registry.rs b/cli/npm/registry.rs index 40d7f6219..eb0a2068a 100644 --- a/cli/npm/registry.rs +++ b/cli/npm/registry.rs @@ -363,7 +363,23 @@ impl CliNpmRegistryApiInner { } fn get_package_url(&self, name: &str) -> Url { - self.base_url.join(name).unwrap() + // list of all characters used in npm packages: + // !, ', (, ), *, -, ., /, [0-9], @, [A-Za-z], _, ~ + const ASCII_SET: percent_encoding::AsciiSet = + percent_encoding::NON_ALPHANUMERIC + .remove(b'!') + .remove(b'\'') + .remove(b'(') + .remove(b')') + .remove(b'*') + .remove(b'-') + .remove(b'.') + .remove(b'/') + .remove(b'@') + .remove(b'_') + .remove(b'~'); + let name = percent_encoding::utf8_percent_encode(name, &ASCII_SET); + self.base_url.join(&name.to_string()).unwrap() } fn get_package_file_cache_path(&self, name: &str) -> PathBuf { |