percentEncode works differently to default encoding
Closed this issue · 1 comments
In version 0.4.2 was a bit surprised to find this:
scala> import com.netaporter.uri.dsl._
import com.netaporter.uri.dsl._
scala> import com.netaporter.uri.encoding.percentEncode
import com.netaporter.uri.encoding.percentEncode
scala> import com.netaporter.uri.config.UriConfig
import com.netaporter.uri.config.UriConfig
scala> ("http://example.com/path" ? ("param" -> "something==")).toString
res0: String = http://example.com/path?param=something==
scala> ("http://example.com/path" ? ("param" -> "something==")).toString(UriConfig(percentEncode))
res1: String = http://example.com/path?param=something%3D%3D
The range of characters covered by percentEncode
seems be wider than the default (unspecified) set. Is that intentional? It surprised me!
Also is a change from 0.4.0, where the default set of encoded characters included =
.
Thanks for raising this. I agree that =
should be percent encoded in query parameters by default as it could otherwise lead to ambiguity. Fixed in 458bf9d
With regards to .toString(UriConfig(percentEncode))
:
By default scala-uri will try to only percent encode the characters necessary for different parts of the URI. For example a ?
in the middle of the path must be percent encoded to avoid it looking like the start of the query string, so scala-uri will do this, however a ?
in query params does have this problem so scala-uri does not percent encode this. Calling .toString(UriConfig(percentEncode))
will use the a single generic percent encoded for the entire URI that is over cautious and percent encodes anything that could be a problem anywhere in the URI.
Maybe percentEncode
is not that useful, just adds confusion and should be removed. That would leave the default behaviour and the percentEncode(chars: Char*)
option where you can be explicit about exactly what you want percent encoded.
WDYT?