Skip to content

Commit

Permalink
esm: do not truncate data: URLs for evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Jul 9, 2024
1 parent 2b068ff commit dcf1a48
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/internal/modules/esm/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function getSource(url, context) {
const { readFile: readFileAsync } = require('internal/fs/promises').exports;
source = await readFileAsync(url);
} else if (protocol === 'data:') {
const match = RegExpPrototypeExec(DATA_URL_PATTERN, url.pathname);
const match = RegExpPrototypeExec(DATA_URL_PATTERN, href);
if (!match) {
throw new ERR_INVALID_URL(responseURL);
}
Expand Down Expand Up @@ -77,7 +77,7 @@ function getSourceSync(url, context) {
if (protocol === 'file:') {
source = readFileSync(url);
} else if (protocol === 'data:') {
const match = RegExpPrototypeExec(DATA_URL_PATTERN, url.pathname);
const match = RegExpPrototypeExec(DATA_URL_PATTERN, href);
if (!match) {
throw new ERR_INVALID_URL(responseURL);
}
Expand Down
5 changes: 5 additions & 0 deletions test/es-module/test-esm-data-urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,9 @@ function createBase64URL(mime, body) {
const plainESMURL = `data:text/javascript,${encodeURIComponent(`import ${JSON.stringify(fixtures.fileURL('es-module-url', 'empty.js'))}`)}`;
await import(plainESMURL);
}
{
const urlWithUnescapedQueryAndHash = 'data:text/javascript,export const value="?query#hash";'
const { value } = await import(urlWithUnescapedQueryAndHash);
assert.strictEqual(value, '?query#hash');
}
})().then(common.mustCall());

0 comments on commit dcf1a48

Please sign in to comment.