NET-A-PORTER/scala-uri

Spaces encoded as '+' characters don't decode

Opened this issue · 2 comments

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 commented

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.

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.