| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -262,18 +262,13 @@ function readPackage(requestPath) { | |||
| 262 | 262 | const existing = packageJsonCache.get(jsonPath); | |
| 263 | 263 | if (existing !== undefined) return existing; | |
| 264 | 264 | ||
| 265 | - const result = packageJsonReader.read(path.toNamespacedPath(jsonPath)); | ||
| 265 | + const result = packageJsonReader.read(jsonPath); | ||
| 266 | 266 | const json = result.containsKeys === false ? '{}' : result.string; | |
| 267 | 267 | if (json === undefined) { | |
| 268 | 268 | packageJsonCache.set(jsonPath, false); | |
| 269 | 269 | return false; | |
| 270 | 270 | } | |
| 271 | 271 | ||
| 272 | - if (manifest) { | ||
| 273 | - const jsonURL = pathToFileURL(jsonPath); | ||
| 274 | - manifest.assertIntegrity(jsonURL, json); | ||
| 275 | - } | ||
| 276 | - | ||
| 277 | 272 | try { | |
| 278 | 273 | const parsed = JSONParse(json); | |
| 279 | 274 | const filtered = { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,10 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | + const { getOptionValue } = require('internal/options'); | ||
| 4 | + const manifest = getOptionValue('--experimental-policy') ? | ||
| 5 | + require('internal/process/policy').manifest : | ||
| 6 | + null; | ||
| 7 | + | ||
| 3 | 8 | const { Buffer } = require('buffer'); | |
| 4 | 9 | ||
| 5 | 10 | const fs = require('fs'); | |
@@ -15,20 +20,22 @@ const DATA_URL_PATTERN = /^[^/]+\/[^,;]+(?:[^,]*?)(;base64)?,([\s\S]*)$/; | |||
| 15 | 20 | ||
| 16 | 21 | async function defaultGetSource(url, { format } = {}, defaultGetSource) { | |
| 17 | 22 | const parsed = new URL(url); | |
| 23 | + let source; | ||
| 18 | 24 | if (parsed.protocol === 'file:') { | |
| 19 | - return { | ||
| 20 | - source: await readFileAsync(parsed) | ||
| 21 | - }; | ||
| 25 | + source = await readFileAsync(parsed); | ||
| 22 | 26 | } else if (parsed.protocol === 'data:') { | |
| 23 | 27 | const match = DATA_URL_PATTERN.exec(parsed.pathname); | |
| 24 | 28 | if (!match) { | |
| 25 | 29 | throw new ERR_INVALID_URL(url); | |
| 26 | 30 | } | |
| 27 | 31 | const [ , base64, body ] = match; | |
| 28 | - return { | ||
| 29 | - source: Buffer.from(body, base64 ? 'base64' : 'utf8') | ||
| 30 | - }; | ||
| 32 | + source = Buffer.from(body, base64 ? 'base64' : 'utf8'); | ||
| 33 | + } else { | ||
| 34 | + throw new ERR_INVALID_URL_SCHEME(['file', 'data']); | ||
| 35 | + } | ||
| 36 | + if (manifest) { | ||
| 37 | + manifest.assertIntegrity(parsed, source); | ||
| 31 | 38 | } | |
| 32 | - throw new ERR_INVALID_URL_SCHEME(['file', 'data']); | ||
| 39 | + return { source }; | ||
| 33 | 40 | } | |
| 34 | 41 | exports.defaultGetSource = defaultGetSource; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,21 +2,35 @@ | |||
| 2 | 2 | ||
| 3 | 3 | const { SafeMap } = primordials; | |
| 4 | 4 | const { internalModuleReadJSON } = internalBinding('fs'); | |
| 5 | + const { pathToFileURL } = require('url'); | ||
| 6 | + const { toNamespacedPath } = require('path'); | ||
| 5 | 7 | ||
| 6 | 8 | const cache = new SafeMap(); | |
| 7 | 9 | ||
| 8 | 10 | /** | |
| 9 | 11 | * | |
| 10 | - * @param {string} path | ||
| 12 | + * @param {string} jsonPath | ||
| 11 | 13 | */ | |
| 12 | - function read(path) { | ||
| 13 | - if (cache.has(path)) { | ||
| 14 | - return cache.get(path); | ||
| 14 | + function read(jsonPath) { | ||
| 15 | + if (cache.has(jsonPath)) { | ||
| 16 | + return cache.get(jsonPath); | ||
| 15 | 17 | } | |
| 16 | 18 | ||
| 17 | - const [string, containsKeys] = internalModuleReadJSON(path); | ||
| 19 | + const [string, containsKeys] = internalModuleReadJSON( | ||
| 20 | + toNamespacedPath(jsonPath) | ||
| 21 | + ); | ||
| 18 | 22 | const result = { string, containsKeys }; | |
| 19 | - cache.set(path, result); | ||
| 23 | + const { getOptionValue } = require('internal/options'); | ||
| 24 | + if (string !== undefined) { | ||
| 25 | + const manifest = getOptionValue('--experimental-policy') ? | ||
| 26 | + require('internal/process/policy').manifest : | ||
| 27 | + null; | ||
| 28 | + if (manifest) { | ||
| 29 | + const jsonURL = pathToFileURL(jsonPath); | ||
| 30 | + manifest.assertIntegrity(jsonURL, string); | ||
| 31 | + } | ||
| 32 | + } | ||
| 33 | + cache.set(jsonPath, result); | ||
| 20 | 34 | return result; | |
| 21 | 35 | } | |
| 22 | 36 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -205,6 +205,9 @@ class Worker extends EventEmitter { | |||
| 205 | 205 | cwdCounter: cwdCounter || workerIo.sharedCwdCounter, | |
| 206 | 206 | workerData: options.workerData, | |
| 207 | 207 | publicPort: port2, | |
| 208 | + manifestURL: getOptionValue('--experimental-policy') ? | ||
| 209 | + require('internal/process/policy').url : | ||
| 210 | + null, | ||
| 208 | 211 | manifestSrc: getOptionValue('--experimental-policy') ? | |
| 209 | 212 | require('internal/process/policy').src : | |
| 210 | 213 | null, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments