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

fix: address decodeURIComponent errors #76

Merged
merged 2 commits into from
Aug 28, 2024

Conversation

jdalton
Copy link
Collaborator

@jdalton jdalton commented Aug 20, 2024

PR to address #75.

I'm still noodling on normalization behavior of the constructor. We may be able to tweak it to how URLSearchParams does it (it must have some encoding detection).

Update:

After reviewing new URL(), and new URLSearchParams() we can avoid decodeURIComponent during normalization and only use it in parseString.

@jdalton jdalton marked this pull request as ready for review August 20, 2024 17:49
function decodeURIComponent(encodedURIComponent) {
try {
return decodeURIComponent_(encodedURIComponent)
} catch {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little worried about this. If somebody writes pkg:generic/whatever#100% it will do what they want, but if somebody writes pkg:generic/whatever#100%/100%25, the subpath will be 100%/100%25 because the decoding error applies to the entire component.

Implementations are inconsistent.

  • error: anchore/packageurl-go, package-url/packageurl-go, package-url/packageurl-java, package-url/packageurl-js (2.0.0), sonatype/package-url-java
  • 100%/100%: althonos/packageurl.rs, giterlizzi/perl-URL-PackageURL, package-url/packageurl-dotnet, package-url/packageurl-php, package-url/packageurl-python, package-url/packageurl-swift, phylum-dev/purl
  • 100%/100%25: maennchen/purl, package-url/packageurl-ruby, package-url/packageurl-js (this code)

It probably doesn't matter because it's an invalid PURL to begin with.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matt-phylum Thank you for digging into this. It is interesting.

new URL('pkg:generic/whatever#100%/100%25').toString()
// -> 'pkg:generic/whatever#100%/100%25'

While

PackageURL.fromString('pkg:generic/whatever#100%/100%25').toString()
-> 'pkg:generic/whatever#100%25/100%2525'

Updated PR to error:

PurlError: Invalid purl: unable to decode "subpath" component

@jdalton jdalton merged commit f7dccd6 into package-url:master Aug 28, 2024
1 check passed
@jdalton jdalton deleted the jdalton/decode-error branch August 28, 2024 01:17
@jdalton
Copy link
Collaborator Author

jdalton commented Sep 3, 2024

@steven-esser could you cut a patch release at your convenience 🙏

@steven-esser
Copy link
Collaborator

@jdalton Will do

@steven-esser
Copy link
Collaborator

@jdalton v2.0.1 published to npmjs: https://www.npmjs.com/package/packageurl-js/v/2.0.1

@jdalton
Copy link
Collaborator Author

jdalton commented Sep 5, 2024

Thank you @steven-esser 🕺

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

Successfully merging this pull request may close these issues.

3 participants