Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module: improve support of data: URLs #37392

Merged
merged 1 commit into from
Feb 18, 2021
Merged
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
3 changes: 2 additions & 1 deletion lib/internal/modules/esm/get_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const {
RegExpPrototypeExec,
decodeURIComponent,
} = primordials;
const { getOptionValue } = require('internal/options');
// Do not eagerly grab .manifest, it may be in TDZ
Expand Down Expand Up @@ -32,7 +33,7 @@ async function defaultGetSource(url, { format } = {}, defaultGetSource) {
throw new ERR_INVALID_URL(url);
}
const { 1: base64, 2: body } = match;
source = Buffer.from(body, base64 ? 'base64' : 'utf8');
source = Buffer.from(decodeURIComponent(body), base64 ? 'base64' : 'utf8');
} else {
throw new ERR_INVALID_URL_SCHEME(['file', 'data']);
}
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 @@ -102,4 +102,9 @@ function createBase64URL(mime, body) {
assert.strictEqual(e.code, 'ERR_INVALID_RETURN_PROPERTY_VALUE');
}
}
{
const plainESMURL = 'data:text/javascript,export%20default%202';
const module = await import(plainESMURL);
assert.strictEqual(module.default, 2);
}
})().then(common.mustCall());