| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0651358 commit bf1525c
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,35 +29,40 @@ const { | |||
| 29 | 29 | ||
| 30 | 30 | const DATA_URL_PATTERN = /^[^/]+\/[^,;]+(?:[^,]*?)(;base64)?,([\s\S]*)$/; | |
| 31 | 31 | ||
| 32 | + /** | ||
| 33 | + * @param {URL} url URL to the module | ||
| 34 | + * @param {ESModuleContext} context used to decorate error messages | ||
| 35 | + * @returns {{ responseURL: string, source: string | BufferView }} | ||
| 36 | + */ | ||
| 32 | 37 | async function getSource(url, context) { | |
| 33 | - const parsed = new URL(url); | ||
| 34 | - let responseURL = url; | ||
| 38 | + const { protocol, href } = url; | ||
| 39 | + let responseURL = href; | ||
| 35 | 40 | let source; | |
| 36 | - if (parsed.protocol === 'file:') { | ||
| 37 | - source = await readFileAsync(parsed); | ||
| 38 | - } else if (parsed.protocol === 'data:') { | ||
| 39 | - const match = RegExpPrototypeExec(DATA_URL_PATTERN, parsed.pathname); | ||
| 41 | + if (protocol === 'file:') { | ||
| 42 | + source = await readFileAsync(url); | ||
| 43 | + } else if (protocol === 'data:') { | ||
| 44 | + const match = RegExpPrototypeExec(DATA_URL_PATTERN, url.pathname); | ||
| 40 | 45 | if (!match) { | |
| 41 | - throw new ERR_INVALID_URL(url); | ||
| 46 | + throw new ERR_INVALID_URL(responseURL); | ||
| 42 | 47 | } | |
| 43 | 48 | const { 1: base64, 2: body } = match; | |
| 44 | 49 | source = BufferFrom(decodeURIComponent(body), base64 ? 'base64' : 'utf8'); | |
| 45 | 50 | } else if (experimentalNetworkImports && ( | |
| 46 | - parsed.protocol === 'https:' || | ||
| 47 | - parsed.protocol === 'http:' | ||
| 51 | + protocol === 'https:' || | ||
| 52 | + protocol === 'http:' | ||
| 48 | 53 | )) { | |
| 49 | - const res = await fetchModule(parsed, context); | ||
| 54 | + const res = await fetchModule(url, context); | ||
| 50 | 55 | source = await res.body; | |
| 51 | 56 | responseURL = res.resolvedHREF; | |
| 52 | 57 | } else { | |
| 53 | 58 | const supportedSchemes = ['file', 'data']; | |
| 54 | 59 | if (experimentalNetworkImports) { | |
| 55 | 60 | ArrayPrototypePush(supportedSchemes, 'http', 'https'); | |
| 56 | 61 | } | |
| 57 | - throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(parsed, supportedSchemes); | ||
| 62 | + throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(url, supportedSchemes); | ||
| 58 | 63 | } | |
| 59 | 64 | if (policy?.manifest) { | |
| 60 | - policy.manifest.assertIntegrity(parsed, source); | ||
| 65 | + policy.manifest.assertIntegrity(href, source); | ||
| 61 | 66 | } | |
| 62 | 67 | return { __proto__: null, responseURL, source }; | |
| 63 | 68 | } | |
@@ -91,7 +96,7 @@ async function defaultLoad(url, context) { | |||
| 91 | 96 | ) { | |
| 92 | 97 | source = null; | |
| 93 | 98 | } else if (source == null) { | |
| 94 | - ({ responseURL, source } = await getSource(url, context)); | ||
| 99 | + ({ responseURL, source } = await getSource(urlInstance, context)); | ||
| 95 | 100 | } | |
| 96 | 101 | ||
| 97 | 102 | return { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments