-
Notifications
You must be signed in to change notification settings - Fork 30.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
esm: Ensure custom loader resolved "url" is properly validated #21352
Changes from 1 commit
bc83382
cf1e32f
6594462
1776edf
888d186
233cf2a
d434368
a235f08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-invalid-url.mjs | ||
/* eslint-disable node-core/required-modules */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move the |
||
import assert from 'assert'; | ||
|
||
import('../fixtures/es-modules/test-esm-ok.mjs') | ||
.then(() => { | ||
assert.fail(); | ||
}, (err) => { | ||
assert.strictEqual(err.code, 'ERR_INVALID_URL'); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume we would want |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export async function resolve(specifier, parentModuleURL, defaultResolve) { | ||
if (parentModuleURL && specifier !== 'assert') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: braces around multi-line condition body |
||
return { | ||
url: specifier, | ||
format: 'esm' | ||
}; | ||
return defaultResolve(specifier, parentModuleURL); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm... I'm not sure what the benefit of the try/catch and additional throw here. If the
url
is invalid,new URL(url)
will throw and accomplish the same thing, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well caught, yes that's simpler. Updated.