mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
esm: identify parent importing a url with invalid host
PR-URL: https://github.com/nodejs/node/pull/49736 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
This commit is contained in:
parent
017998971b
commit
645b788bea
3 changed files with 24 additions and 1 deletions
|
@ -231,7 +231,15 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
|
|||
fileURLToPath(base));
|
||||
}
|
||||
|
||||
const path = fileURLToPath(resolved);
|
||||
let path;
|
||||
try {
|
||||
path = fileURLToPath(resolved);
|
||||
} catch (err) {
|
||||
const { setOwnProperty } = require('internal/util');
|
||||
setOwnProperty(err, 'input', `${resolved}`);
|
||||
setOwnProperty(err, 'module', `${base}`);
|
||||
throw err;
|
||||
}
|
||||
|
||||
const stats = internalModuleStat(toNamespacedPath(StringPrototypeEndsWith(path, '/') ?
|
||||
StringPrototypeSlice(path, -1) : path));
|
||||
|
|
|
@ -49,4 +49,18 @@ describe('default resolver', () => {
|
|||
assert.strictEqual(stdout.trim(), 'index.byoe!');
|
||||
assert.strictEqual(stderr, '');
|
||||
});
|
||||
|
||||
it('should identify the parent module of an invalid URL host in import specifier', async () => {
|
||||
if (process.platform === 'win32') return;
|
||||
|
||||
const { code, stderr } = await spawnPromisified(execPath, [
|
||||
'--no-warnings',
|
||||
fixtures.path('es-modules', 'invalid-posix-host.mjs'),
|
||||
]);
|
||||
|
||||
assert.match(stderr, /ERR_INVALID_FILE_URL_HOST/);
|
||||
assert.match(stderr, /file:\/\/hmm\.js/);
|
||||
assert.match(stderr, /invalid-posix-host\.mjs/);
|
||||
assert.strictEqual(code, 1);
|
||||
});
|
||||
});
|
||||
|
|
1
test/fixtures/es-modules/invalid-posix-host.mjs
vendored
Normal file
1
test/fixtures/es-modules/invalid-posix-host.mjs
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
import "file://hmm.js";
|
Loading…
Add table
Add a link
Reference in a new issue