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