Skip to content

Commit

Permalink
Avoid a NPE when the charset in a content type is empty (#640)
Browse files Browse the repository at this point in the history
* NPE with an empty charset in the content type

* Avoid the NPE when the charset is empty
  • Loading branch information
msprunck authored Apr 15, 2024
1 parent 5158b4e commit b8e4947
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/clj_http/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@
(or v1 v2)))))

(defn- trim-quotes [s]
(clojure.string/replace s #"^\s*(\"(.*)\"|(.*?))\s*$" "$2$3"))
(when s
(clojure.string/replace s #"^\s*(\"(.*)\"|(.*?))\s*$" "$2$3")))

(defn parse-content-type
"Parse `s` as an RFC 2616 media type."
Expand Down
5 changes: 4 additions & 1 deletion test/clj_http/test/util_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
:content-type-params {:charset "utf-8"}}
"text/html; charset=ISO-8859-4"
{:content-type :text/html
:content-type-params {:charset "ISO-8859-4"}}))
:content-type-params {:charset "ISO-8859-4"}}
"text/html; charset="
{:content-type :text/html
:content-type-params {:charset nil}}))

(deftest test-force-byte-array
(testing "empty InputStream returns empty byte-array"
Expand Down

0 comments on commit b8e4947

Please sign in to comment.