Skip to content

Commit 981aa78

Browse files
andremralvestargos
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: #49104Fixes: #48957 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent d585d13 commit 981aa78

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
@@ -38,7 +38,7 @@ if (experimentalWasmModules){
3838
functionmimeToFormat(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';}

‎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+
awaitassert.rejects(import('data:WRONGtext/javascriptFORMAT,console.log("hello!");'),{
22+
code: 'ERR_UNKNOWN_MODULE_FORMAT',
23+
});
2124
})().then(common.mustCall());

0 commit comments

Comments
(0)