From af4c2056a341b7d14ff14b43840f7cbc8a8d2d90 Mon Sep 17 00:00:00 2001 From: Valery Bugakov Date: Wed, 22 Jan 2020 15:11:15 +0530 Subject: [PATCH] Allow dots in bin names (#7811) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed bin regex * Removed unsupported by Windows colon from bin regex * Updated normalize-manifest tests * Update fix.js * Update actual.json * Update normalize-manifest.js.snap Co-authored-by: Maƫl Nison --- .../__snapshots__/normalize-manifest.js.snap | 3 +++ .../dangerous bin name/actual.json | 18 +++++++++++------- .../dangerous bin name/expected.json | 8 +++++--- src/util/normalize-manifest/fix.js | 2 +- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/__tests__/__snapshots__/normalize-manifest.js.snap b/__tests__/__snapshots__/normalize-manifest.js.snap index eb903b98d4..96bece70ad 100644 --- a/__tests__/__snapshots__/normalize-manifest.js.snap +++ b/__tests__/__snapshots__/normalize-manifest.js.snap @@ -62,9 +62,12 @@ Array [ exports[`dangerous bin name: dangerous bin name 1`] = ` Array [ + "foo: Invalid bin entry for \\".\\" (in \\"foo\\").", + "foo: Invalid bin entry for \\"..\\" (in \\"foo\\").", "foo: Invalid bin entry for \\"/tmp/foo\\" (in \\"foo\\").", "foo: Invalid bin entry for \\"../tmp/foo\\" (in \\"foo\\").", "foo: Invalid bin entry for \\"tmp/../../foo\\" (in \\"foo\\").", + "foo: Invalid bin entry for \\"build:cli\\" (in \\"foo\\").", "foo: No license field", ] `; diff --git a/__tests__/fixtures/normalize-manifest/dangerous bin name/actual.json b/__tests__/fixtures/normalize-manifest/dangerous bin name/actual.json index d70ea69e80..2b429e5e9f 100644 --- a/__tests__/fixtures/normalize-manifest/dangerous bin name/actual.json +++ b/__tests__/fixtures/normalize-manifest/dangerous bin name/actual.json @@ -1,9 +1,13 @@ { - "name": "foo", - "version": "", - "bin": { - "/tmp/foo": "main.js", - "../tmp/foo": "main.js", - "tmp/../../foo": "main.js" - } + "name": "foo", + "version": "", + "bin": { + ".": "main.js", + "..": "main.js", + "/tmp/foo": "main.js", + "../tmp/foo": "main.js", + "tmp/../../foo": "main.js", + "build:cli": "main.js", + "build.cli": "main.js" + } } diff --git a/__tests__/fixtures/normalize-manifest/dangerous bin name/expected.json b/__tests__/fixtures/normalize-manifest/dangerous bin name/expected.json index 80ce110c76..b7f6cf75df 100644 --- a/__tests__/fixtures/normalize-manifest/dangerous bin name/expected.json +++ b/__tests__/fixtures/normalize-manifest/dangerous bin name/expected.json @@ -1,5 +1,7 @@ { - "name": "foo", - "version": "", - "bin": {} + "name": "foo", + "version": "", + "bin": { + "build.cli": "main.js" + } } diff --git a/src/util/normalize-manifest/fix.js b/src/util/normalize-manifest/fix.js index 7d9796dee3..ef7b7798d6 100644 --- a/src/util/normalize-manifest/fix.js +++ b/src/util/normalize-manifest/fix.js @@ -12,7 +12,7 @@ const semver = require('semver'); const path = require('path'); const url = require('url'); -const VALID_BIN_KEYS = /^[a-z0-9_-]+$/i; +const VALID_BIN_KEYS = /^(?!\.{0,2}$)[a-z0-9._-]+$/i; const LICENSE_RENAMES: {[key: string]: ?string} = { 'MIT/X11': 'MIT',