Merge pull request #566 from metosin/toni/update-empty-seq-handling-in-query-string

Handle empty seq as empty string in `query-string`
This commit is contained in:
Tommi Reiman 2022-10-16 15:05:21 +03:00 committed by GitHub
commit e84495585c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -249,6 +249,10 @@
(->> params
(map (fn [[k v]]
(if (or (sequential? v) (set? v))
(str/join "&" (map query-parameter (repeat k) v))
(if (seq 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))))
(str/join "&")))

View file

@ -50,6 +50,8 @@
{"a" "b"} "a=b"
{:a 1} "a=1"
{:a nil} "a="
{:a []} "a="
{:a '()} "a="
{:a :b :c "d"} "a=b&c=d"
{:a "b c"} "a=b+c"
{:a ["b" "c"]} "a=b&a=c"