packageurl-js
Advanced tools
Comparing version 2.0.0 to 2.0.1
{ | ||
"name": "packageurl-js", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "JavaScript library to parse and build \"purl\" aka. package URLs. This is a microlibrary implementing the purl spec at https://github.com/package-url", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -5,4 +5,13 @@ 'use strict' | ||
const REUSED_SEARCH_PARAMS = new URLSearchParams() | ||
const REUSED_SEARCH_PARAMS_KEY = '_' | ||
const REUSED_SEARCH_PARAMS_OFFSET = 2 // '_='.length | ||
module.exports = { | ||
LOOP_SENTINEL | ||
LOOP_SENTINEL, | ||
REUSED_SEARCH_PARAMS, | ||
REUSED_SEARCH_PARAMS_KEY, | ||
REUSED_SEARCH_PARAMS_OFFSET | ||
} |
'use strict' | ||
const { | ||
REUSED_SEARCH_PARAMS, | ||
REUSED_SEARCH_PARAMS_KEY, | ||
REUSED_SEARCH_PARAMS_OFFSET | ||
} = require('./constants') | ||
const { isObject } = require('./objects') | ||
const { isNonEmptyString } = require('./strings') | ||
const reusedSearchParams = new URLSearchParams() | ||
const reusedSearchParamKey = '_' | ||
const reusedSearchParamOffset = 2 // '_='.length | ||
const { encodeURIComponent } = globalThis | ||
@@ -25,5 +26,5 @@ | ||
// https://url.spec.whatwg.org/#urlencoded-serializing | ||
reusedSearchParams.set(reusedSearchParamKey, param) | ||
REUSED_SEARCH_PARAMS.set(REUSED_SEARCH_PARAMS_KEY, param) | ||
return replacePlusSignWithPercentEncodedSpace( | ||
reusedSearchParams.toString().slice(reusedSearchParamOffset) | ||
REUSED_SEARCH_PARAMS.toString().slice(REUSED_SEARCH_PARAMS_OFFSET) | ||
) | ||
@@ -30,0 +31,0 @@ } |
@@ -6,8 +6,4 @@ 'use strict' | ||
const { decodeURIComponent } = globalThis | ||
function normalizeName(rawName) { | ||
return typeof rawName === 'string' | ||
? decodeURIComponent(rawName).trim() | ||
: undefined | ||
return typeof rawName === 'string' ? rawName.trim() : undefined | ||
} | ||
@@ -17,3 +13,3 @@ | ||
return typeof rawNamespace === 'string' | ||
? normalizePath(decodeURIComponent(rawNamespace)) | ||
? normalizePath(rawNamespace) | ||
: undefined | ||
@@ -79,3 +75,3 @@ } | ||
return typeof rawSubpath === 'string' | ||
? normalizePath(decodeURIComponent(rawSubpath), subpathFilter) | ||
? normalizePath(rawSubpath, subpathFilter) | ||
: undefined | ||
@@ -88,3 +84,3 @@ } | ||
return typeof rawType === 'string' | ||
? decodeURIComponent(rawType).trim().toLowerCase() | ||
? rawType.trim().toLowerCase() | ||
: undefined | ||
@@ -94,5 +90,3 @@ } | ||
function normalizeVersion(rawVersion) { | ||
return typeof rawVersion === 'string' | ||
? decodeURIComponent(rawVersion).trim() | ||
: undefined | ||
return typeof rawVersion === 'string' ? rawVersion.trim() : undefined | ||
} | ||
@@ -99,0 +93,0 @@ |
@@ -24,2 +24,3 @@ /*! | ||
const { decodePurlComponent } = require('./decode') | ||
const { isObject, recursiveFreeze } = require('./objects') | ||
@@ -31,2 +32,3 @@ const { isBlank, isNonEmptyString, trimLeadingSlashes } = require('./strings') | ||
const { PurlType } = require('./purl-type') | ||
const { PurlError } = require('./error') | ||
@@ -153,3 +155,3 @@ class PackageURL { | ||
} catch (e) { | ||
throw new Error('Invalid purl: failed to parse as URL', { | ||
throw new PurlError('failed to parse as URL', { | ||
cause: e | ||
@@ -161,5 +163,3 @@ }) | ||
if (url?.protocol !== 'pkg:') { | ||
throw new Error( | ||
'Invalid purl: missing required "pkg" scheme component' | ||
) | ||
throw new PurlError('missing required "pkg" scheme component') | ||
} | ||
@@ -172,5 +172,3 @@ // A purl must NOT contain a URL Authority i.e. there is no support for | ||
) { | ||
throw new Error( | ||
'Invalid purl: cannot contain a "user:pass@host:port"' | ||
) | ||
throw new PurlError('cannot contain a "user:pass@host:port"') | ||
} | ||
@@ -180,6 +178,8 @@ | ||
const firstSlashIndex = pathname.indexOf('/') | ||
const rawType = | ||
const rawType = decodePurlComponent( | ||
'type', | ||
firstSlashIndex === -1 | ||
? pathname | ||
: pathname.slice(0, firstSlashIndex) | ||
) | ||
if (firstSlashIndex < 1) { | ||
@@ -213,3 +213,6 @@ return [ | ||
// Split the remainder once from right on '@'. | ||
rawVersion = pathname.slice(atSignIndex + 1) | ||
rawVersion = decodePurlComponent( | ||
'version', | ||
pathname.slice(atSignIndex + 1) | ||
) | ||
} | ||
@@ -222,8 +225,14 @@ | ||
// Split the remainder once from right on '/'. | ||
rawName = beforeVersion | ||
rawName = decodePurlComponent('name', beforeVersion) | ||
} else { | ||
// Split the remainder once from right on '/'. | ||
rawName = beforeVersion.slice(lastSlashIndex + 1) | ||
rawName = decodePurlComponent( | ||
'name', | ||
beforeVersion.slice(lastSlashIndex + 1) | ||
) | ||
// Split the remainder on '/'. | ||
rawNamespace = beforeVersion.slice(0, lastSlashIndex) | ||
rawNamespace = decodePurlComponent( | ||
'namespace', | ||
beforeVersion.slice(0, lastSlashIndex) | ||
) | ||
} | ||
@@ -234,2 +243,5 @@ | ||
if (searchParams.size !== 0) { | ||
searchParams.forEach((value) => | ||
decodePurlComponent('qualifiers', value) | ||
) | ||
// Split the remainder once from right on '?'. | ||
@@ -243,3 +255,3 @@ rawQualifiers = searchParams | ||
// Split the purl string once from right on '#'. | ||
rawSubpath = hash.slice(1) | ||
rawSubpath = decodePurlComponent('subpath', hash.slice(1)) | ||
} | ||
@@ -246,0 +258,0 @@ |
@@ -17,2 +17,3 @@ 'use strict' | ||
const { validateEmptyByType, validateRequiredByType } = require('./validate') | ||
const { PurlError } = require('./error') | ||
@@ -153,4 +154,4 @@ const PurlTypNormalizer = (purl) => purl | ||
if (throws) { | ||
throw new Error( | ||
'Invalid purl: conan requires a "namespace" field when a "channel" qualifier is present.' | ||
throw new PurlError( | ||
'conan requires a "namespace" component when a "channel" qualifier is present' | ||
) | ||
@@ -162,4 +163,4 @@ } | ||
if (throws) { | ||
throw new Error( | ||
'Invalid purl: conan requires a "qualifiers" field when a namespace is present.' | ||
throw new PurlError( | ||
'conan requires a "qualifiers" component when a namespace is present' | ||
) | ||
@@ -196,4 +197,4 @@ } | ||
if (throws) { | ||
throw new Error( | ||
'Invalid purl: golang "version" field starting with a "v" must be followed by a valid semver version' | ||
throw new PurlError( | ||
'golang "version" component starting with a "v" must be followed by a valid semver version' | ||
) | ||
@@ -248,4 +249,4 @@ } | ||
if (throws) { | ||
throw new Error( | ||
'Invalid purl: pub "name" field may only contain [a-z0-9_] characters' | ||
throw new PurlError( | ||
'pub "name" component may only contain [a-z0-9_] characters' | ||
) | ||
@@ -252,0 +253,0 @@ } |
'use strict' | ||
const { PurlError } = require('./error') | ||
const { isNullishOrEmptyString } = require('./lang') | ||
@@ -9,5 +10,3 @@ const { isNonEmptyString } = require('./strings') | ||
if (throws) { | ||
throw new Error( | ||
`Invalid purl: ${type} "${name}" field must be empty.` | ||
) | ||
throw new PurlError(`${type} "${name}" component must be empty`) | ||
} | ||
@@ -36,5 +35,3 @@ return false | ||
if (throws) { | ||
throw new Error( | ||
'Invalid purl: "qualifiers" argument must be an object.' | ||
) | ||
throw new PurlError('"qualifiers" must be an object') | ||
} | ||
@@ -79,4 +76,4 @@ return false | ||
if (throws) { | ||
throw new Error( | ||
`Invalid purl: qualifier "${key}" contains an illegal character.` | ||
throw new PurlError( | ||
`qualifier "${key}" contains an illegal character` | ||
) | ||
@@ -93,3 +90,3 @@ } | ||
if (throws) { | ||
throw new Error(`Invalid purl: "${name}" is a required field.`) | ||
throw new PurlError(`"${name}" is a required component`) | ||
} | ||
@@ -104,3 +101,3 @@ return false | ||
if (throws) { | ||
throw new Error(`Invalid purl: ${type} requires a "${name}" field.`) | ||
throw new PurlError(`${type} requires a "${name}" component`) | ||
} | ||
@@ -117,4 +114,4 @@ return false | ||
if (throws) { | ||
throw new Error( | ||
`Invalid purl: ${name} "${value}" cannot start with a number.` | ||
throw new PurlError( | ||
`${name} "${value}" cannot start with a number` | ||
) | ||
@@ -133,3 +130,3 @@ } | ||
if (throws) { | ||
throw new Error(`Invalid purl: "'${name}" argument must be a string.`) | ||
throw new PurlError(`"'${name}" must be a string`) | ||
} | ||
@@ -170,4 +167,4 @@ return false | ||
if (throws) { | ||
throw new Error( | ||
`Invalid purl: type "${type}" contains an illegal character.` | ||
throw new PurlError( | ||
`type "${type}" contains an illegal character` | ||
) | ||
@@ -174,0 +171,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
57112
20
1447
0