Skip to content

Commit abf5166

Browse files
committed
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 ?.
1 parent fd08dd8 commit abf5166

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

ring-core/src/ring/util/request.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"://"
1111
(get-in request [:headers "host"])
1212
(:uri request)
13-
(when-let [query (:query-string request)]
13+
(when-let [query (not-empty (:query-string request))]
1414
(str "?" query))))
1515

1616
(defn content-type

ring-core/test/ring/util/test/request.clj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
(is (= (request-url {:scheme :https
1818
:uri "/index.html"
1919
:headers {"host" "www.example.com"}})
20+
"https://www.example.com/index.html"))
21+
(is (= (request-url {:scheme :https
22+
:uri "/index.html"
23+
:headers {"host" "www.example.com"}
24+
:query-string ""})
2025
"https://www.example.com/index.html")))
2126

2227
(deftest test-content-type

0 commit comments

Comments
 (0)