Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBradley Farias <bradley.meck@gmail.com>2020-07-17 00:00:21 +0300
committerBradley Farias <bradley.meck@gmail.com>2020-08-05 21:48:59 +0300
commitb04f2b661802adf5fd2c7731cd2d5e0f5cfe16d1 (patch)
treecfc04ce75b54ff36d75e58c1d6c2f6412d3ed042 /lib/internal/modules
parente0d181cf2b690c4f2a4cd797a61d9b69997f4c75 (diff)
policy: increase tests via permutation matrix
PR-URL: https://github.com/nodejs/node/pull/34404 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/internal/modules')
-rw-r--r--lib/internal/modules/cjs/loader.js7
-rw-r--r--lib/internal/modules/esm/get_source.js21
-rw-r--r--lib/internal/modules/package_json_reader.js26
3 files changed, 35 insertions, 19 deletions
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
index de24f6c409c..7566c55799a 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -276,18 +276,13 @@ function readPackage(requestPath) {
const existing = packageJsonCache.get(jsonPath);
if (existing !== undefined) return existing;
- const result = packageJsonReader.read(path.toNamespacedPath(jsonPath));
+ const result = packageJsonReader.read(jsonPath);
const json = result.containsKeys === false ? '{}' : result.string;
if (json === undefined) {
packageJsonCache.set(jsonPath, false);
return false;
}
- if (manifest) {
- const jsonURL = pathToFileURL(jsonPath);
- manifest.assertIntegrity(jsonURL, json);
- }
-
try {
const parsed = JSONParse(json);
const filtered = {
diff --git a/lib/internal/modules/esm/get_source.js b/lib/internal/modules/esm/get_source.js
index 7b2a2f42eab..5e2cc3e09e7 100644
--- a/lib/internal/modules/esm/get_source.js
+++ b/lib/internal/modules/esm/get_source.js
@@ -1,5 +1,10 @@
'use strict';
+const { getOptionValue } = require('internal/options');
+const manifest = getOptionValue('--experimental-policy') ?
+ require('internal/process/policy').manifest :
+ null;
+
const { Buffer } = require('buffer');
const fs = require('fs');
@@ -15,20 +20,22 @@ const DATA_URL_PATTERN = /^[^/]+\/[^,;]+(?:[^,]*?)(;base64)?,([\s\S]*)$/;
async function defaultGetSource(url, { format } = {}, defaultGetSource) {
const parsed = new URL(url);
+ let source;
if (parsed.protocol === 'file:') {
- return {
- source: await readFileAsync(parsed)
- };
+ source = await readFileAsync(parsed);
} else if (parsed.protocol === 'data:') {
const match = DATA_URL_PATTERN.exec(parsed.pathname);
if (!match) {
throw new ERR_INVALID_URL(url);
}
const [ , base64, body ] = match;
- return {
- source: Buffer.from(body, base64 ? 'base64' : 'utf8')
- };
+ source = Buffer.from(body, base64 ? 'base64' : 'utf8');
+ } else {
+ throw new ERR_INVALID_URL_SCHEME(['file', 'data']);
+ }
+ if (manifest) {
+ manifest.assertIntegrity(parsed, source);
}
- throw new ERR_INVALID_URL_SCHEME(['file', 'data']);
+ return { source };
}
exports.defaultGetSource = defaultGetSource;
diff --git a/lib/internal/modules/package_json_reader.js b/lib/internal/modules/package_json_reader.js
index 066047b55eb..25edfee027c 100644
--- a/lib/internal/modules/package_json_reader.js
+++ b/lib/internal/modules/package_json_reader.js
@@ -2,21 +2,35 @@
const { SafeMap } = primordials;
const { internalModuleReadJSON } = internalBinding('fs');
+const { pathToFileURL } = require('url');
+const { toNamespacedPath } = require('path');
const cache = new SafeMap();
/**
*
- * @param {string} path
+ * @param {string} jsonPath
*/
-function read(path) {
- if (cache.has(path)) {
- return cache.get(path);
+function read(jsonPath) {
+ if (cache.has(jsonPath)) {
+ return cache.get(jsonPath);
}
- const [string, containsKeys] = internalModuleReadJSON(path);
+ const [string, containsKeys] = internalModuleReadJSON(
+ toNamespacedPath(jsonPath)
+ );
const result = { string, containsKeys };
- cache.set(path, result);
+ const { getOptionValue } = require('internal/options');
+ if (string !== undefined) {
+ const manifest = getOptionValue('--experimental-policy') ?
+ require('internal/process/policy').manifest :
+ null;
+ if (manifest) {
+ const jsonURL = pathToFileURL(jsonPath);
+ manifest.assertIntegrity(jsonURL, string);
+ }
+ }
+ cache.set(jsonPath, result);
return result;
}