mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 16:31: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
|
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
(defn resolve-routes [raw-routes {:keys [coerce] :as opts}]
|
(defn resolve-routes [raw-routes {:keys [coerce] :as opts}]
|
||||||
(cond->> (->> (walk raw-routes opts) (map-data merge-data))
|
(cond->> (->> (walk raw-routes opts) (map-data merge-data))
|
||||||
coerce (into [] (keep #(coerce % opts)))))
|
coerce (into [] (keep #(coerce % opts)))))
|
||||||
|
|
||||||
(defn path-conflicting-routes [routes opts]
|
(defn path-conflicting-routes [routes opts]
|
||||||
(-> (into {}
|
(-> (into {}
|
||||||
|
|
@ -239,14 +239,19 @@
|
||||||
[params]
|
[params]
|
||||||
(maybe-map-values #(url-encode (into-string %)) 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
|
(defn query-string
|
||||||
"shallow transform of query parameters into query string"
|
"shallow transform of query parameters into query string"
|
||||||
[params]
|
[params]
|
||||||
(->> params
|
(->> params
|
||||||
(map (fn [[k v]]
|
(map (fn [[k v]]
|
||||||
(str (form-encode (into-string k))
|
(if (or (sequential? v) (set? v))
|
||||||
"="
|
(str/join "&" (map query-parameter (repeat k) v))
|
||||||
(form-encode (into-string v)))))
|
(query-parameter k v))))
|
||||||
(str/join "&")))
|
(str/join "&")))
|
||||||
|
|
||||||
(defmacro goog-extend [type base-type ctor & methods]
|
(defmacro goog-extend [type base-type ctor & methods]
|
||||||
|
|
|
||||||
|
|
@ -51,13 +51,11 @@
|
||||||
{:a 1} "a=1"
|
{:a 1} "a=1"
|
||||||
{:a nil} "a="
|
{:a nil} "a="
|
||||||
{:a :b :c "d"} "a=b&c=d"
|
{:a :b :c "d"} "a=b&c=d"
|
||||||
{:a "b c"} "a=b+c"))
|
{:a "b c"} "a=b+c"
|
||||||
|
{:a ["b" "c"]} "a=b&a=c"
|
||||||
; TODO: support seq values?
|
{:a ["c" "b"]} "a=c&a=b"
|
||||||
;{:a ["b" "c"]} "a=b&a=c"
|
{:a (seq [1 2])} "a=1&a=2"
|
||||||
;{:a ["c" "b"]} "a=c&a=b"
|
{:a #{"c" "b"}} "a=b&a=c"))
|
||||||
;{:a (seq [1 2])} "a=1&a=2"
|
|
||||||
;{:a #{"c" "b"}} "a=b&a=c"
|
|
||||||
|
|
||||||
;; test from https://github.com/playframework/playframework -> UriEncodingSpec.scala
|
;; test from https://github.com/playframework/playframework -> UriEncodingSpec.scala
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue