Skip to content
This repository has been archived by the owner on Jan 30, 2019. It is now read-only.

Allow repeated keys in query params #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/cemerick/url.cljx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
[m]
(some->> (seq m)
sort ; sorting makes testing a lot easier :-)
(map (fn [[k v]]
[(url-encode (name k))
"="
(url-encode (str v))]))
(mapcat (fn [[k vs]]
(->> (if (vector? vs) vs [vs])
(map #(vector
(url-encode (name k))
"="
(url-encode (str %)))))))
(interpose "&")
flatten
(apply str)))
Expand All @@ -50,9 +52,15 @@
(when (not (string/blank? qstr))
(some->> (string/split qstr #"&")
seq
(mapcat split-param)
(map url-decode)
(apply hash-map))))
(reduce (fn [params param]
(let [[k v] (map url-decode (split-param param))]
(->> ((fn [vs]
(if vs
(conj (if (vector? vs) vs [vs]) v)
v))
(get params k))
(assoc params k))))
{}))))

(defn- port-str
[protocol port]
Expand Down