Permalink
Browse files

Parameters can be quoted. Strip quotes

  • Loading branch information...
1 parent 45fdca6 commit b77814874ebff8f412ebb2f2adc52c6465d603c4 @osi committed Dec 20, 2011
@@ -184,11 +184,19 @@ private static boolean isSimpleName(String name) {
key = key.trim();
if (key.length() > 0) {
- parameters.put(key, value.trim());
+ parameters.put(key, unquote(value.trim()));
}
}
return parameters;
}
+
+ private static String unquote(String s) {
+ if( s.startsWith("\"") && s.endsWith("\"")) {
+ return s.substring(1, s.length() - 1);
+ }
+
+ return s;
+ }
/**
* Canonical string representation of this media type.
@@ -20,6 +20,10 @@
import java.util.Map;
import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static java.util.Collections.singletonMap;
public class MediaTypeTest extends TestCase {
@@ -131,6 +135,15 @@ public void testParseWithParams() {
assertTrue(gotCharset && gotFoo && gotFoo2);
}
+ // Per http://tools.ietf.org/html/rfc2045#section-5.1 , charset can be in quotes
+ public void testParseWithParamsAndQuotedCharset() {
+ String mimeStringWithParams = "text/html;charset=\"UTF-8\"";
+
+ MediaType type = MediaType.parse(mimeStringWithParams);
+ assertNotNull(type);
+ assertEquals(singletonMap("charset", "UTF-8"), type.getParameters());
+ }
+
/**
* @since TIKA-121
*/

0 comments on commit b778148

Please sign in to comment.