Skip to content

Commit 61488f8

Browse files
author
Pieter van Prooijen
committed
Change missing parameter values to empty strings
Query parameters that lack an an accompanying "=" clause should be given a value of "" rather than nil to ensure type consistency and to make the value truthy. Fixes: ring-clojure/ring#312
1 parent 6fea0ef commit 61488f8

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/ring/util/codec.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
(reduce
143143
(fn [m param]
144144
(if-let [[k v] (str/split param #"=" 2)]
145-
(assoc-conj m (form-decode-str k encoding) (form-decode-str v encoding))
145+
(assoc-conj m (form-decode-str k encoding) (form-decode-str (or v "") encoding))
146146
m))
147147
{}
148148
(str/split encoded #"&")))))

test/ring/util/test/codec.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
"a=b&c=d" {"a" "b" "c" "d"}
6363
"foo+bar" "foo bar"
6464
"a=b+c" {"a" "b c"}
65-
"a=b%2Fc" {"a" "b/c"})
65+
"a=b%2Fc" {"a" "b/c"}
66+
"a=b&c" {"a" "b" "c" ""}
67+
"a=&b=c" {"a" "" "b" "c"}
68+
"a&b=c" {"a" "" "b" "c"})
6669
(is (= (form-decode "a=foo%FE%FF%00%2Fbar" "UTF-16")
6770
{"a" "foo/bar"})))

0 commit comments

Comments
 (0)