NET-A-PORTER / scala-uri

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

document operator precedence #48

Closed mauhiz closed 9 years ago

mauhiz commented 10 years ago

a uri defined with the dsl can lead to surprising results :

scala> "http://host" / "path" / "to" / "resource" ? ("a" -> "1" ) & ("b" -> "2")
res1: com.netaporter.uri.Uri = http://host/path/to/%2Fresource%3Fa%3D1?b=2

As I understand it this is because of Scala operator precedence : & then / then ? and because the & operator is not defined for Tuple2, even with the dsl.

From there two options :

scala> ("http://host" / "path" / "to" / "resource") ? ("a" -> "1" ) & ("b" -> "2")
res2: com.netaporter.uri.Uri = http://host/path/to/resource?a=1&b=2
theon commented 10 years ago

Thanks for raising this. Yes this is a problem with operator order. I think "resource" is parsed a full URI, but need to investigate further. (see #46 which also mentions this bug). I want to improve the DSL to fix this, but you are right, we should document this until then. Added to README.md

mauhiz commented 10 years ago

I see, indeed #46 is quite close to what is happening here.

theon commented 9 years ago

This has now been properly fixed in 0.4.10-SNAPSHOT:

"http://host" / "path" / "to" / "resource" ? ("a" -> "1" ) & ("b" -> "2")
res0: com.netaporter.uri.Uri = http://host/path/to/resource?a=1&b=2