mirror of
https://github.com/square/okhttp.git
synced 2026-01-12 10:23:16 +03:00
Allow duplicated charsets in MediaType
This commit is contained in:
committed by
Jesse Wilson
parent
5bc7de1f49
commit
fb93a578ee
@@ -107,6 +107,11 @@ public class MediaTypeTest {
|
||||
assertEquals("UTF-8", mediaType.charset().name());
|
||||
}
|
||||
|
||||
@Test public void testDuplicatedCharsets() {
|
||||
MediaType mediaType = MediaType.parse("text/plain; charset=utf-8; charset=UTF-8");
|
||||
assertEquals("UTF-8", mediaType.charset().name());
|
||||
}
|
||||
|
||||
@Test public void testMultipleCharsets() {
|
||||
try {
|
||||
MediaType.parse("text/plain; charset=utf-8; charset=utf-16");
|
||||
|
||||
@@ -61,10 +61,13 @@ public final class MediaType {
|
||||
|
||||
String name = parameter.group(1);
|
||||
if (name == null || !name.equalsIgnoreCase("charset")) continue;
|
||||
if (charset != null) throw new IllegalArgumentException("Multiple charsets: " + string);
|
||||
charset = parameter.group(2) != null
|
||||
String charsetParameter = parameter.group(2) != null
|
||||
? parameter.group(2) // Value is a token.
|
||||
: parameter.group(3); // Value is a quoted string.
|
||||
if (charset != null && !charsetParameter.equalsIgnoreCase(charset)) {
|
||||
throw new IllegalArgumentException("Multiple different charsets: " + string);
|
||||
}
|
||||
charset = charsetParameter;
|
||||
}
|
||||
|
||||
return new MediaType(string, type, subtype, charset);
|
||||
|
||||
Reference in New Issue
Block a user