From abf5166f5757f42c32e6915965cac7cb4c4d3f3d Mon Sep 17 00:00:00 2001 From: Viktor Holmberg Date: Wed, 29 Oct 2025 16:00:55 +0100 Subject: [PATCH] Bugfix: Make util/request-url handle empty query string Empty query strings would make request-url insert a trailing ? in the url for no reason. While not strictly invalid, it's a bit ugly. Empty query strings are added by ring.mock.request/request when you pass in an empty map for parameters. This fixes that by checking that the query string is not empty before adding the ?. --- ring-core/src/ring/util/request.clj | 2 +- ring-core/test/ring/util/test/request.clj | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ring-core/src/ring/util/request.clj b/ring-core/src/ring/util/request.clj index ff33fe4f2..08cc65238 100644 --- a/ring-core/src/ring/util/request.clj +++ b/ring-core/src/ring/util/request.clj @@ -10,7 +10,7 @@ "://" (get-in request [:headers "host"]) (:uri request) - (when-let [query (:query-string request)] + (when-let [query (not-empty (:query-string request))] (str "?" query)))) (defn content-type diff --git a/ring-core/test/ring/util/test/request.clj b/ring-core/test/ring/util/test/request.clj index fa0399027..6bdc7236f 100644 --- a/ring-core/test/ring/util/test/request.clj +++ b/ring-core/test/ring/util/test/request.clj @@ -17,6 +17,11 @@ (is (= (request-url {:scheme :https :uri "/index.html" :headers {"host" "www.example.com"}}) + "https://www.example.com/index.html")) + (is (= (request-url {:scheme :https + :uri "/index.html" + :headers {"host" "www.example.com"} + :query-string ""}) "https://www.example.com/index.html"))) (deftest test-content-type