Skip to content

Commit ad5bd1b

Browse files
committed
Improved regular expression.
1 parent a074058 commit ad5bd1b

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/clj_http/client.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@
504504
(defn detect-charset [content-type]
505505
(or
506506
(when-let [found (when content-type
507-
(re-find #"(?i)charset=(.*)" content-type))]
507+
(re-find #"(?i)charset\s*=\s*([^\s]+)" content-type))]
508508
(second found))
509509
"UTF-8"))
510510

test/clj_http/test/client.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,4 +651,5 @@
651651
(is (= "UTF-8"(client/detect-charset "text/html")))
652652
(is (= "GBK"(client/detect-charset "application/json; charset=GBK")))
653653
(is (= "ISO-8859-1" (client/detect-charset "application/json; charset=ISO-8859-1")))
654+
(is (= "ISO-8859-1" (client/detect-charset "application/json; charset = ISO-8859-1")))
654655
(is (= "GB2312" (client/detect-charset "text/html; Charset=GB2312"))))

0 commit comments

Comments
 (0)