Verifying that fast-fail on utf8 works
This commit is contained in:
parent
d76a5ce80e
commit
28bc479417
|
@ -16,6 +16,7 @@ package org.eclipse.jetty.util;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class Utf8StringBuilderTest
|
public class Utf8StringBuilderTest
|
||||||
|
@ -35,14 +36,38 @@ public class Utf8StringBuilderTest
|
||||||
Utf8StringBuilder buffer = new Utf8StringBuilder();
|
Utf8StringBuilder buffer = new Utf8StringBuilder();
|
||||||
buffer.append(bytes,0,bytes.length);
|
buffer.append(bytes,0,bytes.length);
|
||||||
|
|
||||||
assertEquals(i,"not expected",buffer.toString());
|
Assert.fail("Should have thrown a NotUtf8Exception");
|
||||||
}
|
}
|
||||||
catch (Utf8Appendable.NotUtf8Exception e)
|
catch (Utf8Appendable.NotUtf8Exception e)
|
||||||
{
|
{
|
||||||
assertTrue(i,true);
|
// expected path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFastFail() throws Exception
|
||||||
|
{
|
||||||
|
byte[] part1 = TypeUtil.fromHexString("cebae1bdb9cf83cebcceb5");
|
||||||
|
byte[] part2 = TypeUtil.fromHexString("f4908080"); // INVALID
|
||||||
|
byte[] part3 = TypeUtil.fromHexString("656469746564");
|
||||||
|
|
||||||
|
Utf8StringBuilder buffer = new Utf8StringBuilder();
|
||||||
|
// Part 1 is valid
|
||||||
|
buffer.append(part1,0,part1.length);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Part 2 is invalid
|
||||||
|
buffer.append(part2,0,part2.length);
|
||||||
|
Assert.fail("Should have thrown a NotUtf8Exception");
|
||||||
|
}
|
||||||
|
catch (Utf8Appendable.NotUtf8Exception e)
|
||||||
|
{
|
||||||
|
// expected path
|
||||||
|
}
|
||||||
|
// Part 3 is valid
|
||||||
|
buffer.append(part3,0,part3.length);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUtfStringBuilder() throws Exception
|
public void testUtfStringBuilder() throws Exception
|
||||||
|
@ -78,13 +103,14 @@ public class Utf8StringBuilderTest
|
||||||
Utf8StringBuilder buffer = new Utf8StringBuilder();
|
Utf8StringBuilder buffer = new Utf8StringBuilder();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (byte aByte : bytes)
|
for (byte aByte : bytes) {
|
||||||
buffer.append(aByte);
|
buffer.append(aByte);
|
||||||
assertTrue(false);
|
}
|
||||||
|
Assert.fail("Should have resulted in an Utf8Appendable.NotUtf8Exception");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e)
|
catch (Utf8Appendable.NotUtf8Exception e)
|
||||||
{
|
{
|
||||||
assertTrue(true);
|
// expected path
|
||||||
}
|
}
|
||||||
assertEquals("abc\ufffd",buffer.toString());
|
assertEquals("abc\ufffd",buffer.toString());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue