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

Spaces encoded as '+' characters don't decode #126

Open
subourbonite opened this issue May 10, 2017 · 2 comments
Open

Spaces encoded as '+' characters don't decode #126

subourbonite opened this issue May 10, 2017 · 2 comments

Comments

@subourbonite
Copy link

We're running into issues where some upstream systems and browsers are encoding space characters as a '+' in the URL query string. UriConfig can be configured to encode spaces as '+', but I cannot find any way (short of writing my own implementation of UriDecoder) to support parsing those values back out. Am I just missing something obvious that isn't covered in the documentation, or is this an enhancement that could be made?

@theon
Copy link
Contributor

theon commented May 11, 2017

This is a missing feature. For the meantime you can get the desired behaviour like so:

import com.netaporter.uri.decoding.UriDecoder
import com.netaporter.uri.config.UriConfig

object PlusToSpaceDecoder extends UriDecoder { 
  def decode(s: String) = PercentDecoder.decode(s).replace('+', ' ')
}

implicit val c = UriConfig(decoder = PlusToSpaceDecoder)

val uri = Uri.parse("http://example.com?a=b+c")
uri.toString // http://example.com?a=b%20c
uri.toStringRaw // http://example.com?a=b c

I not longer have write access to this repo, so I am going to move scala-uri over to a new home. Once I have done that, I will make this easier and update here.

@subourbonite
Copy link
Author

Thanks! I actually wrote almost that exact same piece of code as a workaround, but wanted to bring it up as something the framework could address more elegantly.

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

No branches or pull requests

2 participants