From b9cbfdbe90e172a14a6af97c2382c740e632d24e Mon Sep 17 00:00:00 2001 From: Viktor Holmberg Date: Tue, 25 Nov 2025 17:17:04 +0100 Subject: [PATCH] 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: https://github.com/ring-clojure/ring/pull/543#issuecomment-3576166085 --- src/ring/mock/request.clj | 2 +- test/ring/mock/request_test.clj | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ring/mock/request.clj b/src/ring/mock/request.clj index c13b04a..2eb5b14 100644 --- a/src/ring/mock/request.clj +++ b/src/ring/mock/request.clj @@ -47,7 +47,7 @@ (defn- combined-query [request params] (let [query (:query-string request)] - (when (or query params) + (when (or query (not-empty params)) (string/join "&" (remove string/blank? [query (encode-params params)]))))) diff --git a/test/ring/mock/request_test.clj b/test/ring/mock/request_test.clj index d9e781b..ffb1804 100644 --- a/test/ring/mock/request_test.clj +++ b/test/ring/mock/request_test.clj @@ -127,7 +127,12 @@ (is (= (-> {} (query-string {:a "b"}) (query-string {:c "d"})) - {:query-string "c=d"})))) + {:query-string "c=d"}))) + (testing "empty params is the same as nil, e.g no query string" + (is (= (:query-string (request :get "/" nil)) + (:query-string (request :get "/" {})) + nil)))) + (deftest test-body (testing "string body"