Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/internal/modules/esm/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const {
ERR_UNSUPPORTED_ESM_URL_SCHEME,
} = require('internal/errors').codes;

const DATA_URL_PATTERN = /^[^/]+\/[^,;]+(?:[^,]*?)(;base64)?,([\s\S]*)$/;
const DATA_URL_PATTERN = /^data:[^/#]+\/[^,;#]+(?:[^,#]*?)(;base64)?,([^#]*)/;

/**
* @param {URL} url URL to the module
Expand All @@ -45,7 +45,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 @@ -84,7 +84,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
3 changes: 3 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,7 @@ function createBase64URL(mime, body) {
const plainESMURL = `data:text/javascript,${encodeURIComponent(`import ${JSON.stringify(fixtures.fileURL('es-module-url', 'empty.js'))}`)}`;
await import(plainESMURL);
}
{
await import('data:text/javascript,\'?\'#~');
}
})().then(common.mustCall());