333481 Handle UCS-4 codepoints in decode and encode

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2811 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2011-02-22 03:41:39 +00:00
parent a4f122930a
commit e66729308d
2 changed files with 42 additions and 2 deletions

View File

@ -173,7 +173,6 @@ public class HttpWriter extends Writer
else if(Character.isLowSurrogate((char)code)) else if(Character.isLowSurrogate((char)code))
{ {
code = Character.toCodePoint((char)_surrogate, (char)code); // UCS-4 code = Character.toCodePoint((char)_surrogate, (char)code); // UCS-4
_surrogate=0; // USED
} }
// else UCS-2 // else UCS-2
else else
@ -264,7 +263,8 @@ public class HttpWriter extends Writer
{ {
buffer[bytes++]=(byte)('?'); buffer[bytes++]=(byte)('?');
} }
_surrogate=0; // USED
if (bytes==buffer.length) if (bytes==buffer.length)
{ {

View File

@ -216,6 +216,46 @@ public class HttpWriterTest
assertArrayEquals(bytes,_bytes.asArray()); assertArrayEquals(bytes,_bytes.asArray());
assertArrayEquals(baos.toByteArray(),_bytes.asArray()); assertArrayEquals(baos.toByteArray(),_bytes.asArray());
} }
@Test
public void testMultiByteOverflowUTF16x2_2() throws Exception
{
_writer.setCharacterEncoding(StringUtil.__UTF8);
final String singleByteStr = "a";
int remainSize = 1;
final String multiByteDuplicateStr = "\uD842\uDF9F";
int adjustSize = -2;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < HttpWriter.MAX_OUTPUT_CHARS + adjustSize; i++)
{
sb.append(singleByteStr);
}
sb.append(multiByteDuplicateStr);
for (int i = 0; i < remainSize; i++)
{
sb.append(singleByteStr);
}
String source = sb.toString();
byte[] bytes = source.getBytes("UTF-8"/* StringUtil.__UTF81 */);
_writer.write(source.toCharArray(),0,source.toCharArray().length);
java.io.ByteArrayOutputStream baos = new
java.io.ByteArrayOutputStream();
java.io.OutputStreamWriter osw = new java.io.OutputStreamWriter(baos/*
,StringUtil.__UTF8 */);
osw.write(source.toCharArray(),0,source.toCharArray().length);
osw.flush();
myReportBytes(bytes);
myReportBytes(baos.toByteArray());
myReportBytes(_bytes.asArray());
assertArrayEquals(bytes,_bytes.asArray());
assertArrayEquals(baos.toByteArray(),_bytes.asArray());
}
private void myReportBytes(byte[] bytes) throws Exception private void myReportBytes(byte[] bytes) throws Exception
{ {