GeezerVison is showing github.com — esm: identify parent importing a url with invalid host · nodejs/node@ed8dd33
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/modules/esm/resolve.js +10-1Lines changed: 10 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -255,7 +255,16 @@ function finalizeResolution(resolved, base, preserveSymlinks) { |
255 | 255 | resolved.pathname, 'must not include encoded "/" or "\\" characters', |
256 | 256 | fileURLToPath(base)); |
257 | 257 |
|
258 | | - let path = fileURLToPath(resolved); |
| 258 | + let path; |
| 259 | + try { |
| 260 | + path = fileURLToPath(resolved); |
| 261 | + } catch (err) { |
| 262 | + const { setOwnProperty } = require('internal/util'); |
| 263 | + setOwnProperty(err, 'input', `${resolved}`); |
| 264 | + setOwnProperty(err, 'module', `${base}`); |
| 265 | + throw err; |
| 266 | + } |
| 267 | + |
259 | 268 | if (getOptionValue('--experimental-specifier-resolution') === 'node') { |
260 | 269 | let file = resolveExtensionsWithTryExactName(resolved); |
261 | 270 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: test/es-module/test-esm-loader-default-resolver.mjs +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -49,4 +49,18 @@ describe('default resolver', () => { |
49 | 49 | assert.strictEqual(stdout.trim(), 'index.byoe!'); |
50 | 50 | assert.strictEqual(stderr, ''); |
51 | 51 | }); |
| 52 | + |
| 53 | + it('should identify the parent module of an invalid URL host in import specifier', async () => { |
| 54 | + if (process.platform === 'win32') return; |
| 55 | + |
| 56 | + const { code, stderr } = await spawnPromisified(execPath, [ |
| 57 | + '--no-warnings', |
| 58 | + fixtures.path('es-modules', 'invalid-posix-host.mjs'), |
| 59 | + ]); |
| 60 | + |
| 61 | + assert.match(stderr, /ERR_INVALID_FILE_URL_HOST/); |
| 62 | + assert.match(stderr, /file:\/\/hmm\.js/); |
| 63 | + assert.match(stderr, /invalid-posix-host\.mjs/); |
| 64 | + assert.strictEqual(code, 1); |
| 65 | + }); |
52 | 66 | }); |
Collapse file
Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import "file://hmm.js"; |