From 3e28e506930b378c786aca3f5bf3c3e219019219 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 22 Jan 2018 09:24:45 -0600 Subject: [PATCH] Issue #2148 - Limit BufferUtil.toDetailString() raw character display to USASCII 7-bit printable characters Signed-off-by: Joakim Erdfelt --- .../main/java/org/eclipse/jetty/util/BufferUtil.java | 6 ++---- .../java/org/eclipse/jetty/util/BufferUtilTest.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java index 0201a174d13..800827a2651 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java @@ -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"); diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/BufferUtilTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/BufferUtilTest.java index 89a1f7e6470..1448d419061 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/BufferUtilTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/BufferUtilTest.java @@ -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")); }