Skip to content

Commit

Permalink
fix: Correctly handle absolute urls that start with a protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
jespertheend committed Jul 14, 2022
1 parent 5540a2c commit 8b56327
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ function resolveImportsMatch(normalizedSpecifier, asURL, specifierMap) {
normalizedSpecifier.startsWith(specifierKey) &&
// * either asURL is null, or asURL is special
(!asURL ||
["ftp", "file", "http", "https", "ws", "wss"].includes(asURL.protocol))
["ftp:", "file:", "http:", "https:", "ws:", "wss:"].includes(asURL.protocol))
) {
// 1. If resolutionResult is null, then throw a TypeError indicating that resolution of specifierKey was blocked by a null entry.
if (resolutionResult === null) {
Expand Down
19 changes: 19 additions & 0 deletions test/resolveModuleSpecifier.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { assertEquals } from "asserts";
import { resolveModuleSpecifier } from "../mod.js";

Deno.test({
name: "resolveModuleSpecifier() with a https specifier",
fn() {
/** @type {import("../mod.js").ParsedImportMap} */
const parsedImportMap = {
imports: {
"https://example.com/": new URL("file:///foo/bar/"),
},
};

const baseUrl = new URL("file:///foo/script.js");

const result = resolveModuleSpecifier(parsedImportMap, baseUrl, "https://example.com/test.js");
assertEquals(result.href, "file:///foo/bar/test.js");
},
});

0 comments on commit 8b56327

Please sign in to comment.