mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
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: https://github.com/nodejs/node/pull/49104 Fixes: https://github.com/nodejs/node/issues/48957 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
parent
b5da2f4dad
commit
71391987f7
2 changed files with 4 additions and 1 deletions
|
@ -26,7 +26,7 @@ if (experimentalWasmModules) {
|
|||
function mimeToFormat(mime) {
|
||||
if (
|
||||
RegExpPrototypeExec(
|
||||
/\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i,
|
||||
/^\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?$/i,
|
||||
mime,
|
||||
) !== null
|
||||
) return 'module';
|
||||
|
|
|
@ -18,4 +18,7 @@ const assert = require('assert');
|
|||
code: 'ERR_UNKNOWN_MODULE_FORMAT',
|
||||
message: 'Unknown module format: text/css for URL data:text/css,.error { color: red; }',
|
||||
});
|
||||
await assert.rejects(import('data:WRONGtext/javascriptFORMAT,console.log("hello!");'), {
|
||||
code: 'ERR_UNKNOWN_MODULE_FORMAT',
|
||||
});
|
||||
})().then(common.mustCall());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue