wtetzner / exploding-fish

A URI library for Clojure
Other
150 stars 12 forks source link

Query segments of uri's not handled correctly. #8

Closed shriphani closed 11 years ago

shriphani commented 11 years ago

I have provided a few examples here:

user=> (uri/resolve-path "http://foo.com/forumdisplay.php?f=25" "showthread.php?t=10")
"http://foo.com/showthread.php?f=25"
user=> (uri/resolve-path "http://foo.com/" "showthread.php?t=10")
"http://foo.com/showthread.php"

For the above examples I would expect: "http://foo.com/showthread.php?t=10" "http://foo.com/showthread.php?t=10"

What is going wrong - is there a quick-fix I could use?

wtetzner commented 11 years ago

resolve-path only resolves the path. The query string isn't part of the path.

You should be able to do this though:

user> (-> "http://foo.com/forumdisplay.php?f=25" (uri/resolve-path "showthread.php") (uri/query "t=10"))
"http://foo.com/showthread.php?t=10"
user> (-> "http://foo.com/" (uri/resolve-path "showthread.php") (uri/query "t=10"))
"http://foo.com/showthread.php?t=10"

You can also set individual query params:

user> (uri/param "http://foo.com/showthread.php?t=25" "t" "10")
"http://foo.com/showthread.php?t=10"
shriphani commented 11 years ago

Yeah that is what I have currently. Would it be better to have a method that resolves uris correctly (like a browser would)?

wtetzner commented 11 years ago

Yeah, that's not a bad idea. Maybe I'll take a look at it tomorrow.

wtetzner commented 11 years ago

This should be fixed. I merged Pull Request #9, and I made a small change to it so you can resolve against types other than String. I'll likely make a new release soon.