Skip to content

Commit

Permalink
Fix #68: accidental URI path decoding in uri-with-query (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
hxtmdev authored Sep 10, 2024
1 parent d2ffc18 commit 132ffc3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Babashka [http-client](https://github.com/babashka/http-client): HTTP client for Clojure and babashka built on java.net.http

## Unreleased

- [#68](https://github.com/babashka/http-client/issues/68) Fix accidental URI path decoding in uri-with-query

## 0.4.20 (2024-08-13)

- [#60](https://github.com/babashka/http-client/issues/60): Minimum Clojure version is now 1.10 instead of 1.11
Expand Down
6 changes: 3 additions & 3 deletions src/babashka/http_client/interceptors.clj
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
(java.net.URI.
(str (.getScheme uri) "://"
(.getAuthority uri)
(.getPath uri)
(.getRawPath uri)
(when-let [nq new-query]
(str "?" nq))
(when-let [f (.getFragment uri)]
Expand All @@ -127,12 +127,12 @@
opts))})

(comment
(def uri (java.net.URI. "https://borkdude:[email protected]:80/?q=1#/dude"))
(def uri (java.net.URI. "https://borkdude:[email protected]:80/single%2felement?q=1#/dude"))
(.getScheme uri) ;;=> https
(.getSchemeSpecificPart uri) ;;=> //foobar.net/?q=1
(.getUserInfo uri) ;;=> nil
(.getAuthority uri) ;;=> "foobar.net"
(.getPath uri) ;;=> "/"
(.getRawPath uri) ;;=> "/single%2felement"
(.getQuery uri) ;;=> q=1
(.getFragment uri) ;;=> nil
(uri-with-query uri "f=dude%26hello"))
Expand Down
8 changes: 4 additions & 4 deletions test/babashka/http_client_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,12 @@
(deftest uri-with-query-params-test
(when (resolve `i/uri-with-query)
(is (=
"https://borkdude:[email protected]:80/?q=%26moo#/dude"
(str (#'i/uri-with-query (java.net.URI. "https://borkdude:[email protected]:80/#/dude")
"https://borkdude:[email protected]:80/single%2felement?q=%26moo#/dude"
(str (#'i/uri-with-query (java.net.URI. "https://borkdude:[email protected]:80/single%2felement#/dude")
"q=%26moo"))))
(is (=
"https://borkdude:[email protected]:80/?q=1&q=%26moo#/dude"
(str (#'i/uri-with-query (java.net.URI. "https://borkdude:[email protected]:80/?q=1#/dude")
"https://borkdude:[email protected]:80/single%2felement?q=1&q=%26moo#/dude"
(str (#'i/uri-with-query (java.net.URI. "https://borkdude:[email protected]:80/single%2felement?q=1#/dude")
"q=%26moo"))))))

(deftest ring-client-test
Expand Down

0 comments on commit 132ffc3

Please sign in to comment.