purescript-contrib/purescript-uri

Should we treat `+` as `%20` in query part?

Closed this issue · 3 comments

paluh commented

I know that it is not compliant with RFC 3986 as it allows only percent encoding of special characters (and explicitly shows how to encode spaces), but unfortunately + is used as space encoding character in query part by many libraries and even browsers (based on RFC-1866 - first sentence in first section!) - situation is quite clearly described in this answer:

https://stackoverflow.com/questions/2678551/when-to-encode-space-to-plus-or-20#answer-47188851

After query decoding phase users of this library are not able to differentiate if + means really decoded %2B or literal + (which was incorrectly used), so maybe we should decode these incorrectly used pluses as %20 before passing query string to decodeURIComponent.

If you agree I can provide appropriate pull request with this change ;-)

paluh commented

I know that this is not a real argument for discussion, but other libs/tools/frameworks do seem to decode + as space in query strings:

Also I've tested on two versions of Firefox and Chromium (latest Firefox nightly 59.0a1 (2017-11-20), Chromium 62.0.3202.89 and Firefox 56.0.2) that this form:

```
<!DOCTYPE html>
<html>
<body>
  <form action=".">
    <input name="name with spaces" value="value with spaces" />
    <input type="submit" value="send" />
  </form>
</body>
</html>
```

results in + in queries. The same behavior is observed when I add explicit enctype=application/x-www-form-urlencoded.

paluh commented

Sorry, I wasn't aware of this closed thread: #25

Should I close this issue?

garyb commented

The new version of the library doesn't fix this specifically, but it's now possible to solve it in a way that is more natural than having to do custom parsing/printing on the whole URI. 🎉