Skip to content

Creating Uri without setting authority leads to unexpected behavior #18

@mikehwang

Description

@mikehwang

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions