JETTY-1153 Default charset/encoding of HTTP POST requests

This commit is contained in:
Jan Bartel 2011-07-07 19:56:17 +10:00
parent a7eabf0757
commit 7908c4e825
3 changed files with 45 additions and 1 deletions

View File

@ -4,6 +4,7 @@ jetty-7.4.4-SNAPSHOT
+ 350397 SelectChannelConnector does not shutdown gracefully + 350397 SelectChannelConnector does not shutdown gracefully
+ 351039 Forward dispatch should retain locale + 351039 Forward dispatch should retain locale
+ 351199 HttpServletResponse.encodeURL() wrongly encodes an url without path when cookies are disabled + 351199 HttpServletResponse.encodeURL() wrongly encodes an url without path when cookies are disabled
+ JETTY-1153 Default charset/encoding of HTTP POST requests
+ JETTY-1380 Jetty Rewrite example does not work in Hightide + JETTY-1380 Jetty Rewrite example does not work in Hightide
jetty-7.4.3.v20110701 01 July 2011 jetty-7.4.3.v20110701 01 July 2011

View File

@ -507,7 +507,14 @@ public class UrlEncoded extends MultiMap
public static void decodeTo(InputStream in, MultiMap map, String charset, int maxLength) public static void decodeTo(InputStream in, MultiMap map, String charset, int maxLength)
throws IOException throws IOException
{ {
if (charset==null || StringUtil.__UTF8.equalsIgnoreCase(charset)) //no charset present, use the configured default
if (charset==null)
{
charset=ENCODING;
}
if (StringUtil.__UTF8.equalsIgnoreCase(charset))
{ {
decodeUtf8To(in,map,maxLength); decodeUtf8To(in,map,maxLength);
return; return;

View File

@ -19,6 +19,7 @@ import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -28,6 +29,19 @@ import org.junit.Test;
*/ */
public class URLEncodedTest public class URLEncodedTest
{ {
/* -------------------------------------------------------------- */
static
{
/*
* Uncomment to set setting the System property to something other than the default of UTF-8.
* Beware however that you will have to @Ignore all the other tests other than testUrlEncodedStream!
System.setProperty("org.eclipse.jetty.util.UrlEncoding.charset", StringUtil.__ISO_8859_1);
*/
}
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
@Test @Test
public void testUrlEncoded() throws UnsupportedEncodingException public void testUrlEncoded() throws UnsupportedEncodingException
@ -160,6 +174,7 @@ public class URLEncodedTest
{StringUtil.__UTF16,StringUtil.__UTF16}, {StringUtil.__UTF16,StringUtil.__UTF16},
}; };
for (int i=0;i<charsets.length;i++) for (int i=0;i<charsets.length;i++)
{ {
ByteArrayInputStream in = new ByteArrayInputStream("name\n=value+%30&name1=&name2&n\u00e3me3=value+3".getBytes(charsets[i][0])); ByteArrayInputStream in = new ByteArrayInputStream("name\n=value+%30&name1=&name2&n\u00e3me3=value+3".getBytes(charsets[i][0]));
@ -184,7 +199,28 @@ public class URLEncodedTest
} }
else else
assertTrue("Charset Shift_JIS not supported by jvm", true); assertTrue("Charset Shift_JIS not supported by jvm", true);
} }
/* -------------------------------------------------------------- */
@Test
public void testCharsetViaSystemProperty ()
throws Exception
{
/*
* Uncomment to test setting a non-UTF-8 default character encoding using the SystemProperty org.eclipse.jetty.util.UrlEncoding.charset.
* You will also need to uncomment the static initializer that sets this SystemProperty near the top of this file.
ByteArrayInputStream in3 = new ByteArrayInputStream("name=libell%E9".getBytes(StringUtil.__ISO_8859_1));
MultiMap m3 = new MultiMap();
UrlEncoded.decodeTo(in3, m3, null, -1);
assertEquals("stream name", "libell\u00E9", m3.getString("name"));
*/
}
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
@Test @Test