Skip to content

Commit ce98226

Browse files
committed
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: nodejs/node#49104 Fixes: nodejs/node#48957 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent d719ef1 commit ce98226

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

graal-nodejs/lib/internal/modules/esm/formats.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if (experimentalWasmModules) {
3838
function mimeToFormat(mime) {
3939
if (
4040
RegExpPrototypeExec(
41-
/\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i,
41+
/^\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?$/i,
4242
mime,
4343
) !== null
4444
) { return 'module'; }

graal-nodejs/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)