wtetzner/exploding-fish

Creating Uri without setting authority leads to unexpected behavior

mikehwang opened this issue · 1 comments

Creating a Uri by map without passing in :authority results in unexpected behavior when using param with that Uri and could manifest when using other functions as well.

If you see in this example:

user=> (def uritest (ef/uri {:scheme "http" :host "localhost" :port 3001 :path "/tags" :query "name=comp&from=0"}))
#'user/uritest
user=> uritest
#<Uri http://localhost:3001/tags?name=comp&from=0>
user=> (str (ef/param uritest "from" 10))
"http:/tags?name=comp&from=10"

The returned string representation of the new Uri is missing the authority portion. This is unexpected and an issue because the map used to construct the original Uri has all the elements necessary to construct the authority portion. I think the expected behavior is for :authority to be constructed if the minimum is there i.e. :host. Or at least give an error or throw an exception (I'm new to Clojure and not sure if exceptions are considered to be the Clojure-way) that having a :host with no :authority is an invalid map. I think the former is the better fix.

Here's an example with :authority set when constructing the original Uri:

user=> (def uritest2 (ef/uri {:scheme "http" :host "localhost" :port 3001 :path "/tags" :query "name=comp&from=0" :authority "localhost:3001"}))
#'user/uritest2
user=> (str (ef/param uritest2 "from" 10))
"http://localhost:3001/tags?name=comp&from=10"

Thanks

This definitely looks like a bug. I'll take a look when I get a chance.