Merge branch 'percent-40' of https://github.com/wmhilton-contrib/unpkg.com into wmhilton-contrib-percent-40

This commit is contained in:
Michael Jackson 2019-04-08 17:38:13 -07:00
commit 59e402a41e
1 changed files with 8 additions and 14 deletions

View File

@ -2,20 +2,14 @@ import url from 'url';
const packageURLFormat = /^\/((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?(\/.*)?$/; const packageURLFormat = /^\/((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?(\/.*)?$/;
function decodeParam(param) { export default function parsePackageURL(originalURL) {
if (param) { let { pathname, search, query } = url.parse(originalURL, true);
try { try {
return decodeURIComponent(param); pathname = decodeURIComponent(pathname);
} catch (error) { } catch (error) {
// Ignore invalid params. return null;
}
} }
return '';
}
export default function parsePackageURL(originalURL) {
const { pathname, search, query } = url.parse(originalURL, true);
const match = packageURLFormat.exec(pathname); const match = packageURLFormat.exec(pathname);
// Disallow invalid URL formats. // Disallow invalid URL formats.
@ -24,8 +18,8 @@ export default function parsePackageURL(originalURL) {
} }
const packageName = match[1]; const packageName = match[1];
const packageVersion = decodeParam(match[2]) || 'latest'; const packageVersion = match[2] || 'latest';
const filename = decodeParam(match[3]); const filename = match[3] || '';
return { return {
// If the URL is /@scope/name@version/file.js?main=browser: // If the URL is /@scope/name@version/file.js?main=browser: