Merge branch 'jetty-9.3.x' into jetty-9.4.x

This commit is contained in:
Joakim Erdfelt 2016-11-14 15:01:02 -07:00
commit 6a4ea05584
2 changed files with 32 additions and 21 deletions

View File

@ -21,7 +21,6 @@ package org.eclipse.jetty.http;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
@ -30,14 +29,11 @@ import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Set;
import org.eclipse.jetty.util.ArrayTrie;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Loader;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.Trie;
import org.eclipse.jetty.util.log.Log;
@ -400,6 +396,12 @@ public class MimeTypes
continue;
}
if(';'==b && state<=8)
{
state = 1;
continue;
}
switch(state)
{
case 0:
@ -408,8 +410,6 @@ public class MimeTypes
quote=true;
break;
}
if (';'==b)
state=1;
break;
case 1: if ('c'==b) state=2; else if (' '!=b) state=0; break;

View File

@ -18,9 +18,11 @@
package org.eclipse.jetty.http;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import org.junit.Test;
@ -76,24 +78,33 @@ public class MimeTypesTest
assertEquals(prefix,expectedMimeType,contentType);
}
private void assertCharsetFromContentType(String contentType, String expectedCharset)
{
assertThat("getCharsetFromContentType(\"" + contentType + "\")",
MimeTypes.getCharsetFromContentType(contentType), is(expectedCharset));
}
@Test
public void testCharsetFromContentType()
{
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar;charset=abc;some=else"));
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar;charset=abc"));
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar ; charset = abc"));
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar ; charset = abc ; some=else"));
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar;other=param;charset=abc;some=else"));
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar;other=param;charset=abc"));
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar other = param ; charset = abc"));
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar other = param ; charset = abc ; some=else"));
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar other = param ; charset = abc"));
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar other = param ; charset = \"abc\" ; some=else"));
assertEquals(null,MimeTypes.getCharsetFromContentType("foo/bar"));
assertEquals("utf-8",MimeTypes.getCharsetFromContentType("foo/bar;charset=uTf8"));
assertEquals("utf-8",MimeTypes.getCharsetFromContentType("foo/bar;other=\"charset=abc\";charset=uTf8"));
assertEquals("utf-8",MimeTypes.getCharsetFromContentType("application/pdf;;; charset=UTF-8"));
assertEquals("utf-8",MimeTypes.getCharsetFromContentType("text/html;charset=utf-8"));
assertCharsetFromContentType("foo/bar;charset=abc;some=else", "abc");
assertCharsetFromContentType("foo/bar;charset=abc", "abc");
assertCharsetFromContentType("foo/bar ; charset = abc", "abc");
assertCharsetFromContentType("foo/bar ; charset = abc ; some=else", "abc");
assertCharsetFromContentType("foo/bar;other=param;charset=abc;some=else", "abc");
assertCharsetFromContentType("foo/bar;other=param;charset=abc", "abc");
assertCharsetFromContentType("foo/bar other = param ; charset = abc", "abc");
assertCharsetFromContentType("foo/bar other = param ; charset = abc ; some=else", "abc");
assertCharsetFromContentType("foo/bar other = param ; charset = abc", "abc");
assertCharsetFromContentType("foo/bar other = param ; charset = \"abc\" ; some=else", "abc");
assertCharsetFromContentType("foo/bar", null);
assertCharsetFromContentType("foo/bar;charset=uTf8", "utf-8");
assertCharsetFromContentType("foo/bar;other=\"charset=abc\";charset=uTf8", "utf-8");
assertCharsetFromContentType("application/pdf; charset=UTF-8", "utf-8");
assertCharsetFromContentType("application/pdf;; charset=UTF-8", "utf-8");
assertCharsetFromContentType("application/pdf;;; charset=UTF-8", "utf-8");
assertCharsetFromContentType("application/pdf;;;; charset=UTF-8", "utf-8");
assertCharsetFromContentType("text/html;charset=utf-8", "utf-8");
}
@Test