Skip to content

Commit be77457

Browse files
committed
Strip quotes from charset
This commit works around a bug in clj-http's detect-charset (see dakrone/clj-http#618), making sure that even when the charset in Content-Type is wrapped in quotes, it can be passed to Charset/forName.
1 parent 408f6d1 commit be77457

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/skyscraper/core.clj

+8-1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@
188188
[s]
189189
(enlive/html-resource (java.io.StringReader. s)))
190190

191+
(defn- strip-quotes
192+
[s]
193+
(if (and (string/starts-with? s "\"")
194+
(string/ends-with? s "\""))
195+
(subs s 1 (dec (count s)))
196+
s))
197+
191198
(defn parse-string
192199
"Parses `body`, a byte-array, as a string encoded with
193200
content-type provided in `headers`. If `try-html?` is true,
@@ -204,7 +211,7 @@
204211
content-type (get all-headers "content-type")
205212
content-type (cond-> content-type
206213
(vector? content-type) first)]
207-
(String. body (Charset/forName (http/detect-charset content-type))))))
214+
(String. body (Charset/forName (strip-quotes (http/detect-charset content-type)))))))
208215

209216
(defn parse-enlive
210217
"Parses a byte array as a Enlive resource."

0 commit comments

Comments
 (0)