pluses in query parameters not getting encoded
Closed this issue · 2 comments
If you pass a query parameter value with a + symbol it does not encode this to %2B.
I would assume this is because + is a legal 'punct' character (http://docs.oracle.com/javase/6/docs/api/java/net/URI.html) and can be used to encode spaces. You'll likely get the same behavior with other characters in those groups as well.
Since these are query parameter values is it fair to assume all such reserved characters should be encoded?
My exact issue can be worked around by manually encoding the parameters myself, but this is a little unclean.
Good point. Thanks!
I'd like a better way to do percent encoding than the current use of java.net.URI
. Maybe something RFC 3986 aware, but I haven't been able to find any existing libraries (suggestions welcome). I think I'll look writing some custom code to do percent encoding and ask for feedback here.
I'd also like to add configuration for the encoding via an `implicit val'. For example the default config would do percent encoding on spaces:
val uri = "http://example.com" ? ("p1" -> "p one")
uri.toString //http://example.com?p1=p%20one
But an implicit val
can be added to encode spaces as pluses:
implicit val uriConfig = DefaultConfig + SpacePlusEncode
val uri = "http://example.com" ? ("p1" -> "p one")
uri.toString //http://example.com?p1=p+one
And similar configs for encoding lists as token separated (p=1,2,3
) vs multiple key value pairs (p=1&one=2&one=3
) etc. What do you think about this approach?
Issue #3 has been merged in. I've also committed some changes to use a custom percent encoding algorithm rather than anything JDK provided to allow customised encoding, for example, encoding spaces as pluses