369602: ignore NotUtf8Exception for decodeToUtf8
This commit is contained in:
parent
f3735fab7b
commit
ee9e195b49
|
@ -461,6 +461,8 @@ public class UrlEncoded extends MultiMap implements Cloneable
|
||||||
// TODO cache of parameter names ???
|
// TODO cache of parameter names ???
|
||||||
int totalLength=0;
|
int totalLength=0;
|
||||||
while ((b=in.read())>=0)
|
while ((b=in.read())>=0)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
switch ((char) b)
|
switch ((char) b)
|
||||||
{
|
{
|
||||||
|
@ -509,6 +511,12 @@ public class UrlEncoded extends MultiMap implements Cloneable
|
||||||
buffer.append((byte)b);
|
buffer.append((byte)b);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch(NotUtf8Exception e)
|
||||||
|
{
|
||||||
|
LOG.warn(e.toString());
|
||||||
|
LOG.debug(e);
|
||||||
|
}
|
||||||
if (maxLength>=0 && (++totalLength > maxLength))
|
if (maxLength>=0 && (++totalLength > maxLength))
|
||||||
throw new IllegalStateException("Form too large");
|
throw new IllegalStateException("Form too large");
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ import java.io.IOException;
|
||||||
**/
|
**/
|
||||||
public abstract class Utf8Appendable
|
public abstract class Utf8Appendable
|
||||||
{
|
{
|
||||||
private final char REPLACEMENT = '\ufffd';
|
public static final char REPLACEMENT = '\ufffd';
|
||||||
private static final int UTF8_ACCEPT = 0;
|
private static final int UTF8_ACCEPT = 0;
|
||||||
private static final int UTF8_REJECT = 12;
|
private static final int UTF8_REJECT = 12;
|
||||||
|
|
||||||
|
|
|
@ -220,7 +220,6 @@ public class URLEncodedTest
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------- */
|
/* -------------------------------------------------------------- */
|
||||||
@Test
|
@Test
|
||||||
public void testUtf8()
|
public void testUtf8()
|
||||||
|
@ -236,4 +235,21 @@ public class URLEncodedTest
|
||||||
String expected = new String(TypeUtil.fromHexString(hex),"utf-8");
|
String expected = new String(TypeUtil.fromHexString(hex),"utf-8");
|
||||||
assertEquals(expected,url_encoded.get("text"));
|
assertEquals(expected,url_encoded.get("text"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------- */
|
||||||
|
@Test
|
||||||
|
public void testNotUtf8() throws Exception
|
||||||
|
{
|
||||||
|
String query="name=X%c0%afZ";
|
||||||
|
|
||||||
|
MultiMap<String> map = new MultiMap<String>();
|
||||||
|
|
||||||
|
UrlEncoded.decodeUtf8To(query.getBytes(StringUtil.__ISO_8859_1),0,query.length(),map);
|
||||||
|
assertEquals("X"+Utf8Appendable.REPLACEMENT+Utf8Appendable.REPLACEMENT+"Z",map.getValue("name",0));
|
||||||
|
|
||||||
|
map.clear();
|
||||||
|
|
||||||
|
UrlEncoded.decodeUtf8To(new ByteArrayInputStream(query.getBytes(StringUtil.__ISO_8859_1)),map,100,2);
|
||||||
|
assertEquals("X"+Utf8Appendable.REPLACEMENT+Utf8Appendable.REPLACEMENT+"Z",map.getValue("name",0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue