From 365207ac969a5f2211e0ad436d7b1477110f0c20 Mon Sep 17 00:00:00 2001 From: Karolis Narkevicius Date: Fri, 8 Sep 2017 18:03:23 +0100 Subject: [PATCH 1/2] Fix the scope regex, allow / in addition to %2f in the url --- __tests__/registries/npm-registry.js | 6 ++++-- src/registries/npm-registry.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/__tests__/registries/npm-registry.js b/__tests__/registries/npm-registry.js index db1df9f3a0..4e2ff1c8d7 100644 --- a/__tests__/registries/npm-registry.js +++ b/__tests__/registries/npm-registry.js @@ -251,7 +251,7 @@ describe('isRequestToRegistry functional test', () => { const packageIdents = [ ['normal', ''], ['@scopedNoPkg', ''], - ['@scoped/notescaped', ''], + ['@scoped/notescaped', '@scoped'], ['not@scope/pkg', ''], ['@scope?query=true', ''], ['@scope%2fpkg', '@scope'], @@ -260,13 +260,15 @@ const packageIdents = [ ['@scope%2fpkg%2f1.2.3', '@scope'], ['http://foo.bar:80/normal', ''], ['http://foo.bar:80/@scopedNoPkg', ''], - ['http://foo.bar:80/@scoped/notescaped', ''], + ['http://foo.bar:80/@scoped/notescaped', '@scoped'], + ['http://foo.bar:80/@scoped/notescaped/download/@scoped/notescaped-1.0.0.tgz', '@scoped'], ['http://foo.bar:80/not@scope/pkg', ''], ['http://foo.bar:80/@scope?query=true', ''], ['http://foo.bar:80/@scope%2fpkg', '@scope'], ['http://foo.bar:80/@scope%2fpkg%2fext', '@scope'], ['http://foo.bar:80/@scope%2fpkg?query=true', '@scope'], ['http://foo.bar:80/@scope%2fpkg%2f1.2.3', '@scope'], + ['http://foo.bar:80/@scope%2fpkg/download/@scope%2fpkg-1.0.0.tgz', '@scope'], ]; describe('isScopedPackage functional test', () => { diff --git a/src/registries/npm-registry.js b/src/registries/npm-registry.js index fdd7c19d64..aec7709436 100644 --- a/src/registries/npm-registry.js +++ b/src/registries/npm-registry.js @@ -27,7 +27,7 @@ export const SCOPE_SEPARATOR = '%2f'; // `(?:^|\/)` Match either the start of the string or a `/` but don't capture // `[^\/?]+?` Match any character that is not '/' or '?' and capture, up until the first occurance of: // `%2f` Match SCOPE_SEPARATOR, the escaped '/', and don't capture -const SCOPED_PKG_REGEXP = /(?:^|\/)(@[^\/?]+?)(?=%2f)/; +const SCOPED_PKG_REGEXP = /(?:^|\/)(@[^\/?]+?)(?=%2f|\/)/; // TODO: Use the method from src/cli/commands/global.js for this instead function getGlobalPrefix(): string { From 64bb9aec67c7189f9da8545d4985c1d6d86afc48 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Tue, 12 Sep 2017 13:50:36 +0100 Subject: [PATCH 2/2] Add more explanation about the inconsistency --- src/registries/npm-registry.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/registries/npm-registry.js b/src/registries/npm-registry.js index 553e07b2a2..90879d9522 100644 --- a/src/registries/npm-registry.js +++ b/src/registries/npm-registry.js @@ -27,7 +27,10 @@ export const SCOPE_SEPARATOR = '%2f'; // All scoped package names are of the format `@scope%2fpkg` from the use of NpmRegistry.escapeName // `(?:^|\/)` Match either the start of the string or a `/` but don't capture // `[^\/?]+?` Match any character that is not '/' or '?' and capture, up until the first occurance of: -// `%2f` Match SCOPE_SEPARATOR, the escaped '/', and don't capture +// `(?=%2f|\/)` Match SCOPE_SEPARATOR, the escaped '/', or a raw `/` and don't capture +// The reason for matching a plain `/` is NPM registry being inconsistent about escaping `/` in +// scoped package names: when you're fetching a tarball, it is not escaped, when you want info +// about the package, it is escaped. const SCOPED_PKG_REGEXP = /(?:^|\/)(@[^\/?]+?)(?=%2f|\/)/; // TODO: Use the method from src/cli/commands/global.js for this instead