Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to construct PURL containing percent signs #75

Closed
matt-phylum opened this issue Aug 20, 2024 · 4 comments
Closed

Unable to construct PURL containing percent signs #75

matt-phylum opened this issue Aug 20, 2024 · 4 comments

Comments

@matt-phylum
Copy link

> const { PackageURL } = await import("packageurl-js");
undefined
> new PackageURL("generic", "100%", "test");
Uncaught URIError: URI malformed
    at decodeURIComponent (<anonymous>)
    at Object.normalizeNamespace [as normalize] (/purl/repo/src/normalize.js:16:25)
    at new PackageURL (/purl/repo/src/package-url.js:50:39)
> new PackageURL("generic", "test", "100%");
Uncaught URIError: URI malformed
    at decodeURIComponent (<anonymous>)
    at Object.normalizeName [as normalize] (/purl/repo/src/normalize.js:10:11)
    at new PackageURL (/purl/repo/src/package-url.js:55:34)
> new PackageURL("generic", "test", "test", "100%");
Uncaught URIError: URI malformed
    at decodeURIComponent (<anonymous>)
    at Object.normalizeVersion [as normalize] (/purl/repo/src/normalize.js:91:11)
    at new PackageURL (/purl/repo/src/package-url.js:60:37)
> new PackageURL("generic", "test", "test", "1.0", {}, "100%");
Uncaught URIError: URI malformed
    at decodeURIComponent (<anonymous>)
    at Object.normalizeSubpath [as normalize] (/purl/repo/src/normalize.js:77:25)
    at new PackageURL (/purl/repo/src/package-url.js:71:37)

Or worse if the percent sign is followed by two or more hex characters:

> new PackageURL("generic", "", "%21").toString();
'pkg:generic/!'

It only works correctly for qualifier values:

> new PackageURL("generic", "test", "test", "1.0", {"a": "100%"}).toString();
'pkg:generic/test/[email protected]?a=100%25'
@jdalton
Copy link
Collaborator

jdalton commented Aug 20, 2024

@matt-phylum Thanks for the find! This happens because in v2 normalization is consistent across constructor and fromString. In v1.x PackageURL.fromString("pkg:general/100%/test") would throw a similar error (because of decodeURIComponent use).

@jdalton

This comment was marked as outdated.

@jdalton
Copy link
Collaborator

jdalton commented Aug 28, 2024

Closed by #76

@jdalton jdalton closed this as completed Aug 28, 2024
@steven-esser
Copy link
Collaborator

v2.0.1 published to npmjs: https://www.npmjs.com/package/packageurl-js/v/2.0.1 with this fix included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants