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:
Joakim Erdfelt 2018-01-22 11:23:54 -06:00 committed by GitHub
commit fe2be81783
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -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");

View File

@ -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"));
}