NET-A-PORTER/scala-uri

Empty parameters should have =

Closed this issue · 3 comments

If I have a url like http://locahost:8888/?x=&y=1

a Uri.parse(url).toString() would result in "http://locahost:8888/?x&y=1"

The "=" is removed. The resulting url is still valid but some query parsers might not parse that url correctly. Is it possible to preserve the "=".

Corresponding code in Parameters.scala
def paramsToString(e: UriEncoder, charset: String) =
params.map(kv => {
val (k,v) = kv
if(v.isEmpty) {
e.encode(k, charset)
} else {
e.encode(k, charset) + "=" + e.encode(v, charset)
}
}).mkString(separator)

The error is in parse: it looks to me as though ?x=&y=1 should be modelled as ("x"->Some("")),("y"->Some("1")) and it is currently modelled as ("x"->None:Option[String]),("y"->Some("1")) which is the correct model for the query ?x&y=1

Thanks @philwill-nap for the quick response on this. When will the next version be pushed to nexus?

@sauravshah this should be released now as version 0.4.5