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:
parent
a4f122930a
commit
e66729308d
|
@ -173,7 +173,6 @@ public class HttpWriter extends Writer
|
|||
else if(Character.isLowSurrogate((char)code))
|
||||
{
|
||||
code = Character.toCodePoint((char)_surrogate, (char)code); // UCS-4
|
||||
_surrogate=0; // USED
|
||||
}
|
||||
// else UCS-2
|
||||
else
|
||||
|
@ -265,6 +264,7 @@ public class HttpWriter extends Writer
|
|||
buffer[bytes++]=(byte)('?');
|
||||
}
|
||||
|
||||
_surrogate=0; // USED
|
||||
|
||||
if (bytes==buffer.length)
|
||||
{
|
||||
|
|
|
@ -217,6 +217,46 @@ public class HttpWriterTest
|
|||
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
|
||||
{
|
||||
for (int i = 0; i < bytes.length; i++)
|
||||
|
|
Loading…
Reference in New Issue