Merge branch 'jetty-9.4.x'

This commit is contained in:
Joakim Erdfelt 2016-11-14 15:01:17 -07:00
commit 5976f88641
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.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URL;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -30,14 +29,11 @@ import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.MissingResourceException;
import java.util.Properties; import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Set; import java.util.Set;
import org.eclipse.jetty.util.ArrayTrie; import org.eclipse.jetty.util.ArrayTrie;
import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Loader;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.Trie; import org.eclipse.jetty.util.Trie;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
@ -399,6 +395,12 @@ public class MimeTypes
quote=false; quote=false;
continue; continue;
} }
if(';'==b && state<=8)
{
state = 1;
continue;
}
switch(state) switch(state)
{ {
@ -408,8 +410,6 @@ public class MimeTypes
quote=true; quote=true;
break; break;
} }
if (';'==b)
state=1;
break; break;
case 1: if ('c'==b) state=2; else if (' '!=b) state=0; 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; package org.eclipse.jetty.http;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import org.junit.Test; import org.junit.Test;
@ -75,25 +77,34 @@ public class MimeTypesTest
assertNotNull(prefix,contentType); assertNotNull(prefix,contentType);
assertEquals(prefix,expectedMimeType,contentType); assertEquals(prefix,expectedMimeType,contentType);
} }
private void assertCharsetFromContentType(String contentType, String expectedCharset)
{
assertThat("getCharsetFromContentType(\"" + contentType + "\")",
MimeTypes.getCharsetFromContentType(contentType), is(expectedCharset));
}
@Test @Test
public void testCharsetFromContentType() public void testCharsetFromContentType()
{ {
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar;charset=abc;some=else")); assertCharsetFromContentType("foo/bar;charset=abc;some=else", "abc");
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar;charset=abc")); assertCharsetFromContentType("foo/bar;charset=abc", "abc");
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar ; charset = abc")); assertCharsetFromContentType("foo/bar ; charset = abc", "abc");
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar ; charset = abc ; some=else")); assertCharsetFromContentType("foo/bar ; charset = abc ; some=else", "abc");
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar;other=param;charset=abc;some=else")); assertCharsetFromContentType("foo/bar;other=param;charset=abc;some=else", "abc");
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar;other=param;charset=abc")); assertCharsetFromContentType("foo/bar;other=param;charset=abc", "abc");
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar other = param ; charset = abc")); assertCharsetFromContentType("foo/bar other = param ; charset = abc", "abc");
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar other = param ; charset = abc ; some=else")); assertCharsetFromContentType("foo/bar other = param ; charset = abc ; some=else", "abc");
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar other = param ; charset = abc")); assertCharsetFromContentType("foo/bar other = param ; charset = abc", "abc");
assertEquals("abc",MimeTypes.getCharsetFromContentType("foo/bar other = param ; charset = \"abc\" ; some=else")); assertCharsetFromContentType("foo/bar other = param ; charset = \"abc\" ; some=else", "abc");
assertEquals(null,MimeTypes.getCharsetFromContentType("foo/bar")); assertCharsetFromContentType("foo/bar", null);
assertEquals("utf-8",MimeTypes.getCharsetFromContentType("foo/bar;charset=uTf8")); assertCharsetFromContentType("foo/bar;charset=uTf8", "utf-8");
assertEquals("utf-8",MimeTypes.getCharsetFromContentType("foo/bar;other=\"charset=abc\";charset=uTf8")); assertCharsetFromContentType("foo/bar;other=\"charset=abc\";charset=uTf8", "utf-8");
assertEquals("utf-8",MimeTypes.getCharsetFromContentType("application/pdf;;; charset=UTF-8")); assertCharsetFromContentType("application/pdf; charset=UTF-8", "utf-8");
assertEquals("utf-8",MimeTypes.getCharsetFromContentType("text/html;charset=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 @Test