fix(resolver): resolve query and fragments with unicode filenames (#1591)

This commit is contained in:
Boshen 2023-11-30 17:01:53 +08:00 committed by GitHub
parent a6142558ce
commit 085021ab85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 1 deletions

View file

@ -34,7 +34,7 @@ impl<'a> Specifier<'a> {
let mut prev = specifier.chars().next().unwrap();
let mut escaped_indexes = vec![];
for (i, c) in specifier.chars().enumerate().skip(skip) {
for (i, c) in specifier.char_indices().skip(skip) {
if c == '?' {
query_start = Some(i);
}

View file

@ -27,6 +27,12 @@ fn resolve() {
("file with fragment", f.clone(), "./main1.js#fragment", f.join("main1.js#fragment")),
("file with fragment and query", f.clone(), "./main1.js#fragment?query", f.join("main1.js#fragment?query")),
("file with query and fragment", f.clone(), "./main1.js?#fragment", f.join("main1.js?#fragment")),
("file with query (unicode)", f.clone(), "./测试.js?query", f.join("测试.js?query")),
("file with fragment (unicode)", f.clone(), "./测试.js#fragment", f.join("测试.js#fragment")),
("file with fragment and query (unicode)", f.clone(), "./测试.js#fragment?query", f.join("测试.js#fragment?query")),
("file with query and fragment (unicode)", f.clone(), "./测试.js?#fragment", f.join("测试.js?#fragment")),
("file in module with query", f.clone(), "m1/a?query", f.join("node_modules/m1/a.js?query")),
("file in module with fragment", f.clone(), "m1/a#fragment", f.join("node_modules/m1/a.js#fragment")),
("file in module with fragment and query", f.clone(), "m1/a#fragment?query", f.join("node_modules/m1/a.js#fragment?query")),
@ -43,6 +49,7 @@ fn resolve() {
("handle fragment edge case (no fragment)", f.clone(), "./no#fragment/#/#", f.join("no#fragment/#/#.js")),
("handle fragment edge case (fragment)", f.clone(), "./no#fragment/#/", f.join("no.js#fragment/#/")),
("handle fragment escaping", f.clone(), "./no\0#fragment/\0#/\0##fragment", f.join("no#fragment/#/#.js#fragment")),
];
for (comment, path, request, expected) in pass {