0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 03:07:54 +01:00

esm: fix import.meta.resolve crash

PR-URL: https://github.com/nodejs/node/pull/55777
Fixes: https://github.com/nodejs/node/issues/55518
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Marco Ippolito 2024-11-11 17:29:16 +01:00 committed by GitHub
parent 8531e072f3
commit 07e2819d5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View File

@ -412,7 +412,10 @@ void BindingData::GetPackageScopeConfig(
}
auto file_url = url::FileURLToPath(realm->env(), *package_json_url);
CHECK(file_url);
if (!file_url) {
url::ThrowInvalidURL(realm->env(), resolved.ToStringView(), std::nullopt);
return;
}
error_context.specifier = resolved.ToString();
auto package_json = GetPackageJSON(realm, *file_url, &error_context);
if (package_json != nullptr) {

View File

@ -106,3 +106,15 @@ await assert.rejects(import('data:text/javascript,export default import.meta.res
stdout: 'http://example.com/\n',
});
}
{
const result = await spawnPromisified(execPath, [
'--no-warnings',
'--experimental-import-meta-resolve',
'--eval',
'import.meta.resolve("foo", "http://example.com/bar.js")',
]);
assert.match(result.stderr, /ERR_INVALID_URL/);
assert.strictEqual(result.stdout, '');
assert.strictEqual(result.code, 1);
}