-
Notifications
You must be signed in to change notification settings - Fork 36
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
Plus signs to spaces. #219
Comments
Thanks for raising this. I'm surprised this isn't already supported and it's definitely something we should support. It'll have to be configurable as we'll need to support both users that want to decode + as spaces and those who want them left as +. The question is what the default behaviour should be? I don't think RFC3986 mentions anything about this. I'm not familiar enough with the WHATWG URL spec to know if it has an opinion, but I'll take a look later today. Opting in would mirror the behaviour for encoding spaces in scala-uri, so maybe that is best for now? Let me know if you have any thoughts. |
Had a read through the WHATWG spec and it's pretty confusing. It looks like it requires space/plus encoding/decoding only for query parameters and only by their Notice how in the note under 6.2. URLSearchParams class, when the
I think in scala-uri we should:
This is backwards compatible and mirrors what we already do this on the encoding side Let me know what you think. I can implement this within the next couple weeks, or feel free to raise a PR if you'd like it sooner 👍 |
Plus has been the encoding for space in a URL for 25 years and I've been using it for 25 years. Nobody would be surprised if you made decoding plus to space and %2B to plus as the default, announce a breaking change, and provided a way to disable. It's been true on every web project I've ever been on. My specific usage case here is in the browser: const render_url = new URL("render", document.location.href);
render_url.searchParams.append("name", $("#name").val());
render_url.searchParams.append("title", $("#title").val());
render_url.searchParams.append("location", $("#location").val());
$("#render").attr("src", render_url.href) I can go and find you the decoding in every web framework out there if you want precedence on this. My intention isn't to be right but rather the incredible weight behind this functionality based on history. |
Rails uses Rack uses Ruby: |
Reading this: https://en.wikipedia.org/wiki/Percent-encoding#The_application/x-www-form-urlencoded_type https://tools.ietf.org/html/rfc1630 (search for "QUERY STRINGS") |
After looking back over a few older related issues, I agree that encoding/decoding space to + in query params should be default; I think this will suit most users of this library. Any users who wish to use I'll release this in version 3.0.0 shortly with a migration note. Related issues:
|
This is now released as version |
Works perfect. Removed all my silly |
Describe the bug
Plus signs aren't being URL decoded to spaces. Looks like there's support for encoding to plus signs from spaces.
To Reproduce
https://scastie.scala-lang.org/mgenereu/KsC9oHBvR5qd84JVublZuA/9
The expected result is space and not a plus sign in the name.
I think I can do the PR for this if it's a confirmed bug.
The text was updated successfully, but these errors were encountered: