Skip to content

Commit

Permalink
policy: fix path to URL conversion
Browse files Browse the repository at this point in the history
PR-URL: #49133
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
  • Loading branch information
aduh95 authored and targos committed Nov 26, 2023
1 parent 4ba11e3 commit d4f26f4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,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 += '/';
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-policy-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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, [
Expand Down

0 comments on commit d4f26f4

Please sign in to comment.