Skip to content

Commit 778bd73

Browse files
committedFeb 21, 2024·
fix(resolver): strictly check input
1 parent 48acc8d commit 778bd73

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed
 

‎src/resolve.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ function _tryModuleResolve(
3737
}
3838
}
3939

40-
function _resolve(id: string, options: ResolveOptions = {}): string {
40+
function _resolve(id: string | URL, options: ResolveOptions = {}): string {
41+
if (typeof id !== "string") {
42+
if (id instanceof URL) {
43+
id = fileURLToPath(id);
44+
} else {
45+
throw new TypeError("input must be a `string` or `URL`");
46+
}
47+
}
48+
4149
// Skip if already has a protocol
4250
if (/(node|data|http|https):/.test(id)) {
4351
return id;
@@ -49,7 +57,7 @@ function _resolve(id: string, options: ResolveOptions = {}): string {
4957
}
5058

5159
// Enable fast path for file urls
52-
if (id.startsWith("file:")) {
60+
if (id.startsWith("file://")) {
5361
id = fileURLToPath(id);
5462
}
5563

0 commit comments

Comments
 (0)
Please sign in to comment.