fix(install): fix the case that package scope contains tilde. (#7049)

* fix(install): fix the case that package name contains tilde.
Close: #7045

* add tests

* emm, let me know why test failed

* overwrite registry config

* check more chars

* remove $
This commit is contained in:
Hanaasagi
2023-11-15 17:31:31 +08:00
committed by GitHub
parent 46955e95ef
commit 056d45cf6b
2 changed files with 31 additions and 1 deletions

View File

@@ -144,16 +144,23 @@ pub inline fn isNPMPackageName(target: string) bool {
'@' => true,
else => return false,
};
var slash_index: usize = 0;
for (target[1..], 0..) |c, i| {
switch (c) {
// Old packages may have capital letters
'A'...'Z', 'a'...'z', '0'...'9', '$', '-', '_', '.' => {},
'A'...'Z', 'a'...'z', '0'...'9', '-', '_', '.' => {},
'/' => {
if (!scoped) return false;
if (slash_index > 0) return false;
slash_index = i + 1;
},
// issue#7045, package "@~3/svelte_mount"
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent#description
// It escapes all characters except: AZ az 09 - _ . ! ~ * ' ( )
'!', '~', '*', '\'', '(', ')' => {
if (!scoped or slash_index > 0) return false;
},
else => return false,
}
}