Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix accidental URI path decoding in uri-with-query #67

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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