NET-A-PORTER / scala-uri

Simple scala library for building and parsing URIs
Other
261 stars 33 forks source link

Doesn't encode '@' by default #94

Closed gsastry closed 8 years ago

gsastry commented 9 years ago

Hi,

I upgraded from 0.4.0 to 0.4.7 and it looks like the toString doesn't encode @ by default anymore, even though it looks like it should.

scala> import com.netaporter.uri.dsl._
import com.netaporter.uri.dsl._

scala> import com.netaporter.uri.encoding._
import com.netaporter.uri.encoding._

scala> import com.netaporter.uri.config._
import com.netaporter.uri.config._

scala> val url = "http://www.test.com"
url: String = http://www.test.com

scala> val params = Seq("email" -> "girish@test.com")
params: Seq[(String, String)] = List((email,girish@test.com))

scala> url.addParams(params)
res0: com.netaporter.uri.Uri = http://www.test.com?email=girish@test.com

scala> url.addParams(params).toString
res1: String = http://www.test.com?email=girish@test.com

scala> implicit val config = UriConfig(encoder = percentEncode)
config: com.netaporter.uri.config.UriConfig = UriConfig(PercentEncoder(Set(*, %, }, ], =, <, &, !, \, |, `, ),  , ", @, ,, ;, ', [, #, {, ?, +, (, :, $, ^, /, >)),PercentEncoder(Set(*, %, }, ], =, <, &, !, \, |, `, ),  , ", @, ,, ;, ', [, #, {, ?, +, (, :, $, ^, /, >)),PercentEncoder(Set(*, %, }, ], =, <, &, !, \, |, `, ),  , ", @, ,, ;, ', [, #, {, ?, +, (, :, $, ^, /, >)),com.netaporter.uri.decoding.PercentDecoder$@e16c1a6,com.netaporter.uri.decoding.PercentDecoder$@e16c1a6,com.netaporter.uri.decoding.PercentDecoder$@e16c1a6,false,UTF-8)

scala> url.addParams(params).toString
res2: String = http://www.test.com?email=girish%40test.com

I have to explicitly use a "custom" UriConfig with the encoder for percentEncode, which should be the default one correct?

Let me know if I'm misunderstanding something here, thanks

theon commented 9 years ago

Hi,

The behaviour changed as part of #42 and 2ed9f953c86d42dd275e2b34c37b9ed78dc73c40. rfc3986 section-3.4 suggests that @ need not be percent encoded in query strings.

pchar       = unreserved / pct-encoded / sub-delims / ":" / "@"
query       = *( pchar / "/" / "?" )

Could you give more details about why you need @ to be percent encoded? I am happy to change the default behaviour to be pragmatic if it makes sense.

You can also use implicit val config = UriConfig.conservative which percent encodes more than is strictly necessary (including @)

theon commented 8 years ago

Closing as this is expected behaviour for newer versions of scala-uri.