Skip to content

Commit 00dbd94

Browse files
andremralvesaduh95
authored andcommitted
lib: fix MIME overmatch in data URLs
This commit adds the delimiters ^ and $ to the regex that matches the MIME types for "data:URLs". Fixes: nodejs#48957
1 parent 9fc5700 commit 00dbd94

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/internal/modules/esm/formats.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if (experimentalWasmModules) {
2626
function mimeToFormat(mime) {
2727
if (
2828
RegExpPrototypeExec(
29-
/\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i,
29+
/^\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?$/i,
3030
mime,
3131
) !== null
3232
) return 'module';

test/es-module/test-esm-invalid-data-urls.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ const assert = require('assert');
1818
code: 'ERR_UNKNOWN_MODULE_FORMAT',
1919
message: 'Unknown module format: text/css for URL data:text/css,.error { color: red; }',
2020
});
21+
await assert.rejects(import('data:WRONGtext/javascriptFORMAT,console.log("hello!");'), {
22+
code: 'ERR_UNKNOWN_MODULE_FORMAT',
23+
});
2124
})().then(common.mustCall());

0 commit comments

Comments
 (0)