Skip to content

Commit

Permalink
fix(resolver): strictly check input
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 21, 2024
1 parent 48acc8d commit 778bd73
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ function _tryModuleResolve(
}
}

function _resolve(id: string, options: ResolveOptions = {}): string {
function _resolve(id: string | URL, options: ResolveOptions = {}): string {
if (typeof id !== "string") {
if (id instanceof URL) {
id = fileURLToPath(id);
} else {
throw new TypeError("input must be a `string` or `URL`");
}
}

// Skip if already has a protocol
if (/(node|data|http|https):/.test(id)) {
return id;
Expand All @@ -49,7 +57,7 @@ function _resolve(id: string, options: ResolveOptions = {}): string {
}

// Enable fast path for file urls
if (id.startsWith("file:")) {
if (id.startsWith("file://")) {
id = fileURLToPath(id);
}

Expand Down

0 comments on commit 778bd73

Please sign in to comment.