Skip to content

Commit b66a3c1

Browse files
andremralvesRafaelGSS
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. PR-URL: #49104 Fixes: #48957 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 31442b9 commit b66a3c1

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/internal/modules/esm/formats.js

+1-1
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

+3
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)