Skip to content

Commit b9cbfdb

Browse files
committed
Make empty params to request give no query string
The previous behaviour was to insert an empty query string for an empty map of params, but leave out the key in case it was nil. This change makes it consistently leave out the :query-string in both cases. The previous behaviour caused problems when using the ring request/request-url function - it would (and still does as of time of writing) add a trailing ? to the url when the empty query string is there. This can be confusing. Discussion: ring-clojure/ring#543 (comment)
1 parent 143f5bc commit b9cbfdb

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/ring/mock/request.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
(defn- combined-query [request params]
4949
(let [query (:query-string request)]
50-
(when (or query params)
50+
(when (or query (not-empty params))
5151
(string/join "&"
5252
(remove string/blank?
5353
[query (encode-params params)])))))

test/ring/mock/request_test.clj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,12 @@
127127
(is (= (-> {}
128128
(query-string {:a "b"})
129129
(query-string {:c "d"}))
130-
{:query-string "c=d"}))))
130+
{:query-string "c=d"})))
131+
(testing "empty params is the same as nil, e.g no query string"
132+
(is (= (:query-string (request :get "/" nil))
133+
(:query-string (request :get "/" {}))
134+
nil))))
135+
131136

132137
(deftest test-body
133138
(testing "string body"

0 commit comments

Comments
 (0)