-
Notifications
You must be signed in to change notification settings - Fork 42
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
Escape reserved symbols in default implementation of toEncodedUrlPiece #119
Conversation
Raised an issue in http-types aristidb/http-types#102 |
Note the comment in implementation of -- | Percent-encoding for URLs (using 'B.Builder').
urlEncodeBuilder
:: Bool -- ^ Whether input is in query string. True: Query string, False: Path element
Also I checked using Server:
and
The request looks like:
So plus is not escaped. |
@phadej Hm, but servant-client uses this exacly this method to encode query parameters. It seems that ToHttpApiData should provide some way for encoding query params, if this is done with toEncodedUrlPiece, maybe it should percent-encode these characters Your example doesn't contradict presence of the problem, curl left plus signs intact, as is, but if you would inspect the values in server like php or servant, they would replace plus in second case i.e. server would see param value as |
>>> parseQueryParam @Text "foo+bar"
Right "foo+bar"
I'd like to see a proper reproducer, I'm not convinced the problem is in |
Wait, you said
And that is the cause, it's wrong. Fix |
@phadej As I understand from examples in the docs |
Alright, maybe you right, also some people might rely on current behavior of toEncodedUrlPiece, but it looks like a design flaw that ToHttpData only provides way to encode pieces not params |
Hi) I was investigating an issue with our application where filters wouldn't work correctly if the user enters a plus sign. First I noticed that at some point HTTP request is sent to an endpoint that contains unescaped plus signs, for example if user types
"foo+bar@gmail.com"
the request would be like"GET /?search_by=foo+bar@gmail.com"
(with plus symbol unescaped). We are using servant and servant-client libraries between our backends, I dug deeper into servant-client internals and everything points to default implementation oftoEncodedUrlPiece
method being the root cause of the problem.Actually the real source might be further down the stack in the
http-types
package where I also going to send a pull request, but I suggest you to merge this changes here as well. CurrentlytoEncodedUrlPiece
usesencodePathSegmentsRelative
which under the hood callsurlEncodeBuilder False
which is wrong, because it doesn't escape characters:@&=+$,
and the documentation for toEncodedUrlPiece clearly states that it should escape all special characters