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

Uri: inconsistent query param names (url-encode) when .renderString-ing #7127 #7241

Closed
wants to merge 3 commits into from

Conversation

tothpeti
Copy link

@tothpeti tothpeti commented Aug 17, 2023

This PR fixes #7127

The origin of the issue was that when we create a Uri object, the passed query value(s) doesn't get encoded. This causes the inconsistency that is mentioned in the Issue desciption.

@mergify mergify bot added series/0.23 PRs targeting 0.23.x module:core labels Aug 17, 2023
Comment on lines 1074 to 1077
test("Uri.renderString should Encode special chars in the query") {
val u = Uri(path = Uri.Path.Root).withQueryParam("foo", " !$&'()*+,;=:/?@~")
assertEquals(u.renderString, "/?foo=%20%21%24%26%27%28%29%2A%2B%2C%3B%3D%3A/?%40~")
}
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, why did we remove this test? Is it asserting some wrong behavior?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, correct. It was good for the old QueryNoEncode characters, but for the new ones, this test case is no longer needed.

@@ -24,7 +24,7 @@ import java.nio.charset.{Charset => JCharset}
/* Exists to work around circular dependencies */
private[http4s] object UriCoding {
val Unreserved: CharPredicate = AlphaNum ++ "-_.~"
val QueryNoEncode: CharPredicate = Unreserved ++ "?/"
val QueryNoEncode: CharPredicate = Unreserved ++ "!$&'()*+,;=:/?@"
Copy link
Member

Choose a reason for hiding this comment

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

JFTR, the current implementation is the same as defined in Wikipedia 🤔

Copy link
Author

@tothpeti tothpeti Aug 18, 2023

Choose a reason for hiding this comment

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

Yes, I know it. I found several articles that says otherwise like in the one that I linked in the PR description. However, if @armanbilge says the same thing as you that we should stay with the one that Wikipedia "approves". Then I will redo my changes and will modify my solution. :)

Copy link
Author

@tothpeti tothpeti Aug 19, 2023

Choose a reason for hiding this comment

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

@danicheg Updated the PR. Probably the checks will fail on two test cases:

  1. The first failing test is this one:

    test("Use lazy query model parsing in uri parsing") {

    This should not be accepted as valid uri during parsing: https://en.wikipedia.org/wiki/Query_string#URL_encoding:~:text=The%20series%20of%20pairs%20is%20separated

  2. The second failing test is:

    test("Uri toString should handle brackets in query string") {

    This should not be accepted anymore, because brackets should be encoded in the query parameters

What do you think, what should we do with these? Should i make them pass, or should I remove them?

@tothpeti tothpeti requested a review from danicheg August 19, 2023 14:00
@tothpeti
Copy link
Author

I need to close this PR, because the branch bugged on my side. Opening a new one.

@tothpeti tothpeti closed this Aug 21, 2023
@tothpeti
Copy link
Author

New PR: #7243

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:core series/0.23 PRs targeting 0.23.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uri: inconsistent query param names (url-encode) when .renderString-ing
3 participants