Skip to content

Commit

Permalink
lib: fix MIME overmatch in data URLs
Browse files Browse the repository at this point in the history
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 <webadmin@geoffreybooth.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
sercher committed Apr 25, 2024
1 parent d719ef1 commit ce98226
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion graal-nodejs/lib/internal/modules/esm/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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'; }
Expand Down
3 changes: 3 additions & 0 deletions graal-nodejs/test/es-module/test-esm-invalid-data-urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());

0 comments on commit ce98226

Please sign in to comment.