From dab574e93761c327d80d551da381f60b29d3436f Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 23 Oct 2021 05:37:17 +0000 Subject: [PATCH] policy: fix message for invalid manifest specifier Add test for invalid manifest specifier and fix the error message which is missing a space ("singletrailing" instead of "single trailing"). PR-URL: https://github.com/nodejs/node/pull/40574 Reviewed-By: Antoine du Hamel Reviewed-By: Colin Ihrig Reviewed-By: Zijian Liu Reviewed-By: Luigi Pinca Reviewed-By: Bradley Farias Reviewed-By: James M Snell Reviewed-By: Voltrex --- lib/internal/policy/manifest.js | 5 ++--- test/fixtures/policy-manifest/invalid.json | 9 ++++++++ test/parallel/test-policy-manifest.js | 25 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/policy-manifest/invalid.json create mode 100644 test/parallel/test-policy-manifest.js diff --git a/lib/internal/policy/manifest.js b/lib/internal/policy/manifest.js index 42ff63e87dc9cf..a601113182674e 100644 --- a/lib/internal/policy/manifest.js +++ b/lib/internal/policy/manifest.js @@ -136,9 +136,8 @@ class DependencyMapperInstance { if (!target) { throw new ERR_MANIFEST_INVALID_SPECIFIER( this.href, - target + - ', pattern needs to have a single' + - 'trailing "*" in target'); + `${target}, pattern needs to have a single trailing "*" in target` + ); } const prefix = target[1]; const suffix = target[2]; diff --git a/test/fixtures/policy-manifest/invalid.json b/test/fixtures/policy-manifest/invalid.json new file mode 100644 index 00000000000000..a8a0deb2cf7e07 --- /dev/null +++ b/test/fixtures/policy-manifest/invalid.json @@ -0,0 +1,9 @@ +{ + "resources": { + "./fhqwhgads.js": { + "dependencies": { + "**": true + } + } + } +} diff --git a/test/parallel/test-policy-manifest.js b/test/parallel/test-policy-manifest.js new file mode 100644 index 00000000000000..a8494175f3e68f --- /dev/null +++ b/test/parallel/test-policy-manifest.js @@ -0,0 +1,25 @@ +'use strict'; + +const common = require('../common'); + +if (!common.hasCrypto) + common.skip('missing crypto'); + +common.requireNoPackageJSONAbove(); + +const assert = require('assert'); +const { spawnSync } = require('child_process'); +const fixtures = require('../common/fixtures.js'); + +const policyFilepath = fixtures.path('policy-manifest', 'invalid.json'); + +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 "\*"/);