From 6740f76d175b04941a159b07c83b22f0bbde29f5 Mon Sep 17 00:00:00 2001 From: William Hilton Date: Wed, 2 Jan 2019 15:32:09 -0500 Subject: [PATCH 1/2] fix: decode `%40` before splitting URLs by `@` --- modules/utils/parsePackageURL.js | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/modules/utils/parsePackageURL.js b/modules/utils/parsePackageURL.js index 9220639..eea3629 100644 --- a/modules/utils/parsePackageURL.js +++ b/modules/utils/parsePackageURL.js @@ -2,20 +2,13 @@ const url = require('url'); const packageURLFormat = /^\/((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?(\/.*)?$/; -function decodeParam(param) { - if (param) { - try { - return decodeURIComponent(param); - } catch (error) { - // Ignore invalid params. - } - } - - return ''; -} - function parsePackageURL(originalURL) { const { pathname, search, query } = url.parse(originalURL, true); + try { + pathname = decodeURIComponent(pathname); + } catch (error) { + return null; + } const match = packageURLFormat.exec(pathname); // Disallow invalid URL formats. @@ -24,8 +17,8 @@ function parsePackageURL(originalURL) { } const packageName = match[1]; - const packageVersion = decodeParam(match[2]) || 'latest'; - const filename = decodeParam(match[3]); + const packageVersion = match[2] || 'latest'; + const filename = match[3] || ''; return { // If the URL is /@scope/name@version/file.js?main=browser: From 6a126115bc72d6edad67a88d837ef7e5748fd9d0 Mon Sep 17 00:00:00 2001 From: William Hilton Date: Wed, 2 Jan 2019 15:56:24 -0500 Subject: [PATCH 2/2] fix const error --- modules/utils/parsePackageURL.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/utils/parsePackageURL.js b/modules/utils/parsePackageURL.js index eea3629..eba7903 100644 --- a/modules/utils/parsePackageURL.js +++ b/modules/utils/parsePackageURL.js @@ -3,7 +3,7 @@ const url = require('url'); const packageURLFormat = /^\/((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?(\/.*)?$/; function parsePackageURL(originalURL) { - const { pathname, search, query } = url.parse(originalURL, true); + let { pathname, search, query } = url.parse(originalURL, true); try { pathname = decodeURIComponent(pathname); } catch (error) {