summaryrefslogtreecommitdiff
path: root/cli/npm/registry.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-06-15 20:36:33 +0200
committerGitHub <noreply@github.com>2023-06-15 18:36:33 +0000
commit0733943fe7de30fa54d6cd8ee34f7393e8bb7482 (patch)
treea4eab892bdc6c93b0e66590d619e172d2d2dcdbe /cli/npm/registry.rs
parentfa63fd4610fbe4a1d95c4da776e4a1cfa8f8e0b9 (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.rs18
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 {