| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b95bb38 commit c10ee5d
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1936,6 +1936,11 @@ An attempt was made to load a module with an unknown or unsupported format. | |||
| 1936 | 1936 | An invalid or unknown process signal was passed to an API expecting a valid | |
| 1937 | 1937 | signal (such as [`subprocess.kill()`][]). | |
| 1938 | 1938 | ||
| 1939 | + <a id="ERR_UNSUPPORTED_ESM_URL_SCHEME"></a> | ||
| 1940 | + ### `ERR_UNSUPPORTED_ESM_URL_SCHEME` | ||
| 1941 | + | ||
| 1942 | + `import` with URL schemes other than `file` and `data` is unsupported. | ||
| 1943 | + | ||
| 1939 | 1944 | <a id="ERR_V8BREAKITERATOR"></a> | |
| 1940 | 1945 | ### `ERR_V8BREAKITERATOR` | |
| 1941 | 1946 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1218,6 +1218,8 @@ E('ERR_UNKNOWN_FILE_EXTENSION', | |||
| 1218 | 1218 | TypeError); | |
| 1219 | 1219 | E('ERR_UNKNOWN_MODULE_FORMAT', 'Unknown module format: %s', RangeError); | |
| 1220 | 1220 | E('ERR_UNKNOWN_SIGNAL', 'Unknown signal: %s', TypeError); | |
| 1221 | + E('ERR_UNSUPPORTED_ESM_URL_SCHEME', 'Only file and data URLs are supported ' + | ||
| 1222 | + 'by the default ESM loader', Error); | ||
| 1221 | 1223 | ||
| 1222 | 1224 | E('ERR_V8BREAKITERATOR', | |
| 1223 | 1225 | 'Full ICU data not installed. See https://github.com/nodejs/node/wiki/Intl', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,8 @@ const { resolve: moduleWrapResolve, | |||
| 17 | 17 | getPackageType } = internalBinding('module_wrap'); | |
| 18 | 18 | const { URL, pathToFileURL, fileURLToPath } = require('internal/url'); | |
| 19 | 19 | const { ERR_INPUT_TYPE_NOT_ALLOWED, | |
| 20 | - ERR_UNKNOWN_FILE_EXTENSION } = require('internal/errors').codes; | ||
| 20 | + ERR_UNKNOWN_FILE_EXTENSION, | ||
| 21 | + ERR_UNSUPPORTED_ESM_URL_SCHEME } = require('internal/errors').codes; | ||
| 21 | 22 | ||
| 22 | 23 | const { SafeMap } = primordials; | |
| 23 | 24 | ||
@@ -50,8 +51,9 @@ if (experimentalJsonModules) | |||
| 50 | 51 | extensionFormatMap['.json'] = legacyExtensionFormatMap['.json'] = 'json'; | |
| 51 | 52 | ||
| 52 | 53 | function resolve(specifier, parentURL) { | |
| 54 | + let parsed; | ||
| 53 | 55 | try { | |
| 54 | - const parsed = new URL(specifier); | ||
| 56 | + parsed = new URL(specifier); | ||
| 55 | 57 | if (parsed.protocol === 'data:') { | |
| 56 | 58 | const [ , mime ] = /^([^/]+\/[^;,]+)(?:[^,]*?)(;base64)?,/.exec(parsed.pathname) || [ null, null, null ]; | |
| 57 | 59 | const format = ({ | |
@@ -66,6 +68,8 @@ function resolve(specifier, parentURL) { | |||
| 66 | 68 | }; | |
| 67 | 69 | } | |
| 68 | 70 | } catch {} | |
| 71 | + if (parsed && parsed.protocol !== 'file:' && parsed.protocol !== 'data:') | ||
| 72 | + throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(); | ||
| 69 | 73 | if (NativeModule.canBeRequiredByUsers(specifier)) { | |
| 70 | 74 | return { | |
| 71 | 75 | url: specifier, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,8 +17,8 @@ function expectErrorProperty(result, propertyKey, value) { | |||
| 17 | 17 | })); | |
| 18 | 18 | } | |
| 19 | 19 | ||
| 20 | - function expectMissingModuleError(result) { | ||
| 21 | - expectErrorProperty(result, 'code', 'ERR_MODULE_NOT_FOUND'); | ||
| 20 | + function expectModuleError(result, err) { | ||
| 21 | + expectErrorProperty(result, 'code', err); | ||
| 22 | 22 | } | |
| 23 | 23 | ||
| 24 | 24 | function expectOkNamespace(result) { | |
@@ -55,10 +55,10 @@ function expectFsNamespace(result) { | |||
| 55 | 55 | expectFsNamespace(eval('import("fs")')); | |
| 56 | 56 | expectFsNamespace(eval('import("fs")')); | |
| 57 | 57 | ||
| 58 | - expectMissingModuleError(import('./not-an-existing-module.mjs')); | ||
| 59 | - // TODO(jkrems): Right now this doesn't hit a protocol error because the | ||
| 60 | - // module resolution step already rejects it. These arguably should be | ||
| 61 | - // protocol errors. | ||
| 62 | - expectMissingModuleError(import('node:fs')); | ||
| 63 | - expectMissingModuleError(import('http://example.com/foo.js')); | ||
| 58 | + expectModuleError(import('./not-an-existing-module.mjs'), | ||
| 59 | + 'ERR_MODULE_NOT_FOUND'); | ||
| 60 | + expectModuleError(import('node:fs'), | ||
| 61 | + 'ERR_UNSUPPORTED_ESM_URL_SCHEME'); | ||
| 62 | + expectModuleError(import('http://example.com/foo.js'), | ||
| 63 | + 'ERR_UNSUPPORTED_ESM_URL_SCHEME'); | ||
| 64 | 64 | })(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments