mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 17:01:11 +00:00
Handle empty seq as empty string in query-string
example:
instead of
```clojure
(query-string {:nil nil
:vec []
:seq-empty '()})
;; => "nil=&&"
```
now
```clojure
(query-string {:nil nil
:vec []
:seq-empty '()})
;; => "nil=&vec=&seq-empty="
```
This commit is contained in:
parent
3dff4c84aa
commit
c69b4cde3a
2 changed files with 7 additions and 1 deletions
|
|
@ -249,6 +249,10 @@
|
||||||
(->> params
|
(->> params
|
||||||
(map (fn [[k v]]
|
(map (fn [[k v]]
|
||||||
(if (or (sequential? v) (set? v))
|
(if (or (sequential? v) (set? v))
|
||||||
|
(if (seq v)
|
||||||
(str/join "&" (map query-parameter (repeat k) v))
|
(str/join "&" (map query-parameter (repeat k) v))
|
||||||
|
;; Empty seq results in single & character in the query string.
|
||||||
|
;; Handle as empty string to behave similarly as when the value is nil.
|
||||||
|
(query-parameter k ""))
|
||||||
(query-parameter k v))))
|
(query-parameter k v))))
|
||||||
(str/join "&")))
|
(str/join "&")))
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,8 @@
|
||||||
{"a" "b"} "a=b"
|
{"a" "b"} "a=b"
|
||||||
{:a 1} "a=1"
|
{:a 1} "a=1"
|
||||||
{:a nil} "a="
|
{:a nil} "a="
|
||||||
|
{:a []} "a="
|
||||||
|
{:a '()} "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"
|
{:a ["b" "c"]} "a=b&a=c"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue