Skip to content
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
7 changes: 5 additions & 2 deletions lib/internal/modules/esm/get_source.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict';

const {
decodeURIComponent,
} = primordials;
const { getOptionValue } = require('internal/options');
const manifest = getOptionValue('--experimental-policy') ?
require('internal/process/policy').manifest :
Expand Down Expand Up @@ -28,8 +31,8 @@ async function defaultGetSource(url, { format } = {}, defaultGetSource) {
if (!match) {
throw new ERR_INVALID_URL(url);
}
const [ , base64, body ] = match;
source = Buffer.from(body, base64 ? 'base64' : 'utf8');
const { 1: base64, 2: body } = match;
source = Buffer.from(decodeURIComponent(body), base64 ? 'base64' : 'utf8');
} else {
throw new ERR_INVALID_URL_SCHEME(['file', 'data']);
}
Expand Down
10 changes: 10 additions & 0 deletions lib/internal/per_context/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ primordials.SafePromise = makeSafe(
class SafePromise extends Promise {}
);

// Create copies of URI handling functions
[
decodeURI,
decodeURIComponent,
encodeURI,
encodeURIComponent,
].forEach((fn) => {
primordials[fn.name] = fn;
});

// Create copies of the namespace objects
[
'JSON',
Expand Down
1 change: 1 addition & 0 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
Symbol,
SymbolIterator,
SymbolToStringTag,
decodeURIComponent,
} = primordials;

const { inspect } = require('internal/util/inspect');
Expand Down
1 change: 1 addition & 0 deletions lib/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const {
MathAbs,
ObjectCreate,
ObjectKeys,
decodeURIComponent,
} = primordials;

const { Buffer } = require('buffer');
Expand Down
1 change: 1 addition & 0 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {
ObjectCreate,
ObjectKeys,
SafeSet,
decodeURIComponent,
} = primordials;

const { toASCII } = require('internal/idna');
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());