From 5051c75a5b2eea3b938f6a8204710f731fbb9e94 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 26 Aug 2023 07:45:13 +0200 Subject: [PATCH] policy: fix path to URL conversion PR-URL: https://github.com/nodejs/node/pull/49133 Reviewed-By: Moshe Atlow --- lib/internal/process/pre_execution.js | 2 +- test/parallel/test-policy-manifest.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/internal/process/pre_execution.js b/lib/internal/process/pre_execution.js index 89b916a6ee66ae..0627b06be89c2b 100644 --- a/lib/internal/process/pre_execution.js +++ b/lib/internal/process/pre_execution.js @@ -606,7 +606,7 @@ function readPolicyFromDisk() { // no bare specifiers for now let manifestURL; if (require('path').isAbsolute(experimentalPolicy)) { - manifestURL = new URL(`file://${experimentalPolicy}`); + manifestURL = pathToFileURL(experimentalPolicy); } else { const cwdURL = pathToFileURL(process.cwd()); cwdURL.pathname += '/'; diff --git a/test/parallel/test-policy-manifest.js b/test/parallel/test-policy-manifest.js index 3f5057ff4a2cd4..3c4b1695d28835 100644 --- a/test/parallel/test-policy-manifest.js +++ b/test/parallel/test-policy-manifest.js @@ -9,7 +9,9 @@ common.requireNoPackageJSONAbove(); const assert = require('assert'); const { spawnSync } = require('child_process'); +const { cpSync, rmSync } = require('fs'); const fixtures = require('../common/fixtures.js'); +const tmpdir = require('../common/tmpdir.js'); { const policyFilepath = fixtures.path('policy-manifest', 'invalid.json'); @@ -25,6 +27,23 @@ const fixtures = require('../common/fixtures.js'); assert.match(stderr, /pattern needs to have a single trailing "\*"/); } +{ + tmpdir.refresh(); + const policyFilepath = tmpdir.resolve('file with % in its name.json'); + cpSync(fixtures.path('policy-manifest', 'invalid.json'), policyFilepath); + const result = spawnSync(process.execPath, [ + '--experimental-policy', + policyFilepath, + './fhqwhgads.js', + ]); + + assert.notStrictEqual(result.status, 0); + const stderr = result.stderr.toString(); + assert.match(stderr, /ERR_MANIFEST_INVALID_SPECIFIER/); + assert.match(stderr, /pattern needs to have a single trailing "\*"/); + rmSync(policyFilepath); +} + { const policyFilepath = fixtures.path('policy-manifest', 'onerror-exit.json'); const result = spawnSync(process.execPath, [