mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +00:00
Implement encoding of multi-valued query params.
This commit is contained in:
parent
0adb820bba
commit
6d5bf64833
2 changed files with 14 additions and 11 deletions
|
|
@ -239,14 +239,19 @@
|
|||
[params]
|
||||
(maybe-map-values #(url-encode (into-string %)) params))
|
||||
|
||||
(defn- query-parameter [k v]
|
||||
(str (form-encode (into-string k))
|
||||
"="
|
||||
(form-encode (into-string v))))
|
||||
|
||||
(defn query-string
|
||||
"shallow transform of query parameters into query string"
|
||||
[params]
|
||||
(->> params
|
||||
(map (fn [[k v]]
|
||||
(str (form-encode (into-string k))
|
||||
"="
|
||||
(form-encode (into-string v)))))
|
||||
(if (or (sequential? v) (set? v))
|
||||
(str/join "&" (map query-parameter (repeat k) v))
|
||||
(query-parameter k v))))
|
||||
(str/join "&")))
|
||||
|
||||
(defmacro goog-extend [type base-type ctor & methods]
|
||||
|
|
|
|||
|
|
@ -51,13 +51,11 @@
|
|||
{:a 1} "a=1"
|
||||
{:a nil} "a="
|
||||
{:a :b :c "d"} "a=b&c=d"
|
||||
{:a "b c"} "a=b+c"))
|
||||
|
||||
; TODO: support seq values?
|
||||
;{:a ["b" "c"]} "a=b&a=c"
|
||||
;{:a ["c" "b"]} "a=c&a=b"
|
||||
;{:a (seq [1 2])} "a=1&a=2"
|
||||
;{:a #{"c" "b"}} "a=b&a=c"
|
||||
{:a "b c"} "a=b+c"
|
||||
{:a ["b" "c"]} "a=b&a=c"
|
||||
{:a ["c" "b"]} "a=c&a=b"
|
||||
{:a (seq [1 2])} "a=1&a=2"
|
||||
{:a #{"c" "b"}} "a=b&a=c"))
|
||||
|
||||
;; test from https://github.com/playframework/playframework -> UriEncodingSpec.scala
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue