Skip to content

Commit 4cbe990

Browse files
Handle charsets that are quoted as if they were not (trim them). I encountered some sites that have charset="utf-8" instead of charset=utf-8 and can not access their content. All browsers however accept the charset.
Testcases: 1.) parseCharset("\"utf-8\"") == "utf-8" 2.) parseCharset("'utf-8'") == "utf-8"
1 parent 0de073a commit 4cbe990

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/main/java/com/ning/http/util/AsyncHttpProviderUtils.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,14 @@ public static String parseCharset(String contentType) {
429429
if (part.trim().startsWith("charset=")) {
430430
String[] val = part.split("=");
431431
if (val.length > 1) {
432-
return val[1].trim();
432+
String charset = val[1].trim();
433+
// Quite a lot of sites have charset="CHARSET",
434+
// e.g. charset="utf-8". Note the quotes. This is
435+
// not correct, but client should be able to handle
436+
// it (all browsers do, Apache HTTP Client and Grizzly
437+
// strip it by default)
438+
// This is a poor man's trim("\"").trim("'")
439+
return charset.replaceAll("\"", "").replaceAll("'", "")
433440
}
434441
}
435442
}

0 commit comments

Comments
 (0)