Skip to content

Commit 5051c75

Browse files
aduh95UlisesGascon
authored andcommittedSep 10, 2023
policy: fix path to URL conversion
PR-URL: #49133 Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent d19c710 commit 5051c75

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
 

‎lib/internal/process/pre_execution.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ function readPolicyFromDisk() {
606606
// no bare specifiers for now
607607
let manifestURL;
608608
if (require('path').isAbsolute(experimentalPolicy)) {
609-
manifestURL = new URL(`file://${experimentalPolicy}`);
609+
manifestURL = pathToFileURL(experimentalPolicy);
610610
} else {
611611
const cwdURL = pathToFileURL(process.cwd());
612612
cwdURL.pathname += '/';

‎test/parallel/test-policy-manifest.js

+19
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ common.requireNoPackageJSONAbove();
99

1010
const assert = require('assert');
1111
const { spawnSync } = require('child_process');
12+
const { cpSync, rmSync } = require('fs');
1213
const fixtures = require('../common/fixtures.js');
14+
const tmpdir = require('../common/tmpdir.js');
1315

1416
{
1517
const policyFilepath = fixtures.path('policy-manifest', 'invalid.json');
@@ -25,6 +27,23 @@ const fixtures = require('../common/fixtures.js');
2527
assert.match(stderr, /pattern needs to have a single trailing "\*"/);
2628
}
2729

30+
{
31+
tmpdir.refresh();
32+
const policyFilepath = tmpdir.resolve('file with % in its name.json');
33+
cpSync(fixtures.path('policy-manifest', 'invalid.json'), policyFilepath);
34+
const result = spawnSync(process.execPath, [
35+
'--experimental-policy',
36+
policyFilepath,
37+
'./fhqwhgads.js',
38+
]);
39+
40+
assert.notStrictEqual(result.status, 0);
41+
const stderr = result.stderr.toString();
42+
assert.match(stderr, /ERR_MANIFEST_INVALID_SPECIFIER/);
43+
assert.match(stderr, /pattern needs to have a single trailing "\*"/);
44+
rmSync(policyFilepath);
45+
}
46+
2847
{
2948
const policyFilepath = fixtures.path('policy-manifest', 'onerror-exit.json');
3049
const result = spawnSync(process.execPath, [

0 commit comments

Comments
 (0)