-
Notifications
You must be signed in to change notification settings - Fork 21
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
Conversation
3bf1f9c
to
4c3bf8c
Compare
4c3bf8c
to
b17f575
Compare
function decodeURIComponent(encodedURIComponent) { | ||
try { | ||
return decodeURIComponent_(encodedURIComponent) | ||
} catch {} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
ab2f960
to
6dd4e51
Compare
@steven-esser could you cut a patch release at your convenience 🙏 |
@jdalton Will do |
@jdalton |
Thank you @steven-esser 🕺 |
PR to address #75.
I'm still noodling on normalization behavior of the constructor. We may be able to tweak it to howURLSearchParams
does it (it must have some encoding detection).Update:
After reviewing
new URL()
, andnew URLSearchParams()
we can avoiddecodeURIComponent
during normalization and only use it inparseString
.