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 UlisesGascon committed Sep 10, 2023
1 parent d19c710 commit 5051c75
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
Expand Up @@ -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 += '/';
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-policy-manifest.js
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 5051c75

Please sign in to comment.