Skip to content

Commit

Permalink
fixup! module: improve error message for invalid data URL
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Apr 2, 2021
1 parent a609fcc commit f5ed39f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/internal/modules/esm/loader.js
Expand Up @@ -116,7 +116,7 @@ class Loader {
);
throw new ERR_INVALID_MODULE_SPECIFIER(
url,
dataUrl ? `unsupported MIME "${dataUrl[1]}"` : '');
dataUrl ? `has an unsupported MIME type "${dataUrl[1]}"` : '');
}
if (typeof format !== 'string') {
throw new ERR_INVALID_RETURN_PROPERTY_VALUE(
Expand Down
14 changes: 8 additions & 6 deletions test/es-module/test-esm-invalid-data-urls.js
Expand Up @@ -6,17 +6,19 @@ const assert = require('assert');
await assert.rejects(import('data:text/plain,export default0'), {
code: 'ERR_INVALID_MODULE_SPECIFIER',
message:
'Invalid module "data:text/plain,export default0" unsupported MIME ' +
'"text/plain"',
'Invalid module "data:text/plain,export default0" has an unsupported ' +
'MIME type "text/plain"',
});
await assert.rejects(import('data:text/plain;base64,'), {
code: 'ERR_INVALID_MODULE_SPECIFIER',
message: 'Invalid module "data:text/plain;base64," unsupported MIME ' +
'"text/plain"',
message:
'Invalid module "data:text/plain;base64," has an unsupported ' +
'MIME type "text/plain"',
});
await assert.rejects(import('data:application/json,[]'), {
code: 'ERR_INVALID_MODULE_SPECIFIER',
message: 'Invalid module "data:application/json,[]" unsupported MIME ' +
'"application/json"',
message:
'Invalid module "data:application/json,[]" has an unsupported ' +
'MIME type "application/json"',
});
})().then(common.mustCall());

0 comments on commit f5ed39f

Please sign in to comment.