mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
module: improve support of data: URLs
Add support for loading modules using percent-encoded URLs. PR-URL: https://github.com/nodejs/node/pull/37392 Backport-PR-URL: https://github.com/nodejs/node/pull/37859 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
This commit is contained in:
parent
2da24ac302
commit
7b0ed4ba92
|
|
@ -1,5 +1,8 @@
|
|||
'use strict';
|
||||
|
||||
const {
|
||||
decodeURIComponent,
|
||||
} = primordials;
|
||||
const { getOptionValue } = require('internal/options');
|
||||
const manifest = getOptionValue('--experimental-policy') ?
|
||||
require('internal/process/policy').manifest :
|
||||
|
|
@ -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']);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user