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

Changed space of + into proper url code #90

Closed
wants to merge 1 commit into from

Conversation

Razikus
Copy link

@Razikus Razikus commented Jan 25, 2023

Obviously a bug
%20 is space

@pablogalegoc
Copy link
Contributor

Hello @stevespringett! Do you think this PR could be merged? It's a very simple change and without it we can't rely on the equality check with pURLs generated by this library. Thank you in advance and thank you @Razikus for opening it.

@stevespringett
Copy link
Member

Thanks for the PR. Looks like unit tests are failing.
https://app.travis-ci.com/github/package-url/packageurl-java/builds/260013012

@pablogalegoc
Copy link
Contributor

Indeed, after looking at the failing test I believe the issue is a bit more complex than just substituting "%20" for "%2B".
According to the spec, a pURL is a URL that conforms to RFC 3986 (1). However, the current implementation is not encoding in conformance with RFC 3986 because of URLEncoder:

* Encodes the input in conformance with RFC 3986.
*
* @param input the String to encode
* @return an encoded String
*/
private String percentEncode(final String input) {
try {
return URLEncoder.encode(input, UTF8)
.replace("+", "%20")
// "*" is a reserved character in RFC 3986.
.replace("*", "%2A")
// "~" is an unreserved character in RFC 3986.
.replace("%7E", "~");

URLEncoder doesn't mention any RFC in the documentation and makes some substitutions (like "+" for " ") that are the cause of those .replace() calls. I'm not aware of a standard library class for Java 8 that encodes a string following RFC 3986, but we can take inspiration from Spring's UriUtils for a simple implementation.

@Razikus do you think you can take a look at this? I can do it if you don't have the time 🙂

@stevespringett
Copy link
Member

Closing as resolved and fixed with #98

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