Merge pull request #2149 from eclipse/jetty-9.4.x-2148-bufferutil-todetailstring
Issue #2148 - Limit BufferUtil.toDetailString() raw character display to USASCII 7-bit printable characters
This commit is contained in:
commit
fe2be81783
|
@ -19,12 +19,10 @@
|
|||
package org.eclipse.jetty.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.Buffer;
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
@ -1096,8 +1094,8 @@ public class BufferUtil
|
|||
private static void appendContentChar(StringBuilder buf, byte b)
|
||||
{
|
||||
if (b == '\\')
|
||||
buf.append("\\\\");
|
||||
else if (b >= ' ')
|
||||
buf.append("\\\\");
|
||||
else if ((b >= 0x20) && (b<=0x7E)) // limit to 7-bit printable US-ASCII character space
|
||||
buf.append((char)b);
|
||||
else if (b == '\r')
|
||||
buf.append("\\r");
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.eclipse.jetty.util;
|
||||
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -325,7 +326,18 @@ public class BufferUtilTest
|
|||
assertEquals(64, b3.capacity());
|
||||
assertEquals("Cruel", BufferUtil.toString(b3));
|
||||
assertEquals(0, b3.arrayOffset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToDetail_WithDEL()
|
||||
{
|
||||
ByteBuffer b = ByteBuffer.allocate(40);
|
||||
b.putChar('a').putChar('b').putChar('c');
|
||||
b.put((byte)0x7F);
|
||||
b.putChar('x').putChar('y').putChar('z');
|
||||
b.flip();
|
||||
String result = BufferUtil.toDetailString(b);
|
||||
assertThat("result", result, containsString("\\x7f"));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue