Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow nil query values #14

Closed
vincentjames501 opened this Issue · 2 comments

2 participants

@vincentjames501

First I'd like to say awesome project! We have a project using Stripes and we are trying to parse a referrer header using cemerick. The issue here is that this is a valid url and should be parsed as such.

(url "http://localhost/icmobile/actions/User.action?listAllPageShow=")
=> IllegalArgumentException No value supplied for key: listAllPageShow

I think we should adjust the internal query->map function as follows:

(defn- augment 
    [query-vector]
    (if (= 1 (count query-vector))
        [(first query-vector) nil]
        query-vector))

(defn- query->map
  [qstr]
  (when qstr
    (-?>> (.split qstr "&")
      seq
      (mapcat #(.split % "="))
      (map url-decode)
      (augment)
      (apply hash-map))))

such that the output is now:

(url "http://localhost/icmobile/actions/User.action?listAllPageShow=abc")
=> #cemerick.url.URL{:protocol "http", :username nil, :password nil, :host "localhost", :port -1, :path "/icmobile/actions/User.action", :query {"listAllPageShow" "abc"}, :anchor nil}
(url "http://localhost/icmobile/actions/User.action?listAllPageShow=")
=> #cemerick.url.URL{:protocol "http", :username nil, :password nil, :host "localhost", :port -1, :path "/icmobile/actions/User.action", :query {"listAllPageShow" nil}, :anchor nil}

I'm not a Clojure expert which is why I'm not submitting this as a pull request. If you feel this is acceptable, I'd be happy to submit a pull request.

@cemerick
Owner

Looks reasonable. PR welcome.

@vincentjames501

Closing as this looks to be resolved in 0.1.1, I was using an older version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.