diff options
author | Paul Pazderski | 2020-05-24 11:10:24 +0000 |
---|---|---|
committer | Paul Pazderski | 2020-06-30 16:52:46 +0000 |
commit | df0a30251c7d67951b24884e2c3cc71c4bb69b3e (patch) | |
tree | c1e80a25a67f85648766366783245633d8bdf16b | |
parent | f624f1e041e6e85acf4d750fd92b5d08c5cca71a (diff) | |
download | eclipse.platform.debug-df0a30251c7d67951b24884e2c3cc71c4bb69b3e.tar.gz eclipse.platform.debug-df0a30251c7d67951b24884e2c3cc71c4bb69b3e.tar.xz eclipse.platform.debug-df0a30251c7d67951b24884e2c3cc71c4bb69b3e.zip |
Bug 306131 - [console] Null byte to stdout results in truncation of lineY20200703-0300Y20200701-1200Y20200701-0020I20200702-2150I20200702-1800I20200701-2350I20200701-2210I20200701-1800I20200701-0330I20200630-1800
If interpretation of ASCII control characters is enabled handle null
bytes (\0) by simply filtering them out. This is useful because null
bytes can truncate console lines on some platforms and brings unexpected
results on copy text on most platforms.
Change-Id: Ic6a46c3eba4582c8f54fcd6735b8763738d47623
Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
-rw-r--r-- | org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTests.java | 20 | ||||
-rw-r--r-- | org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java | 12 |
2 files changed, 30 insertions, 2 deletions
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTests.java index a90cad29a..ae51f9f7f 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTests.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTests.java @@ -612,6 +612,26 @@ public class IOConsoleTests extends AbstractDebugTest { } /** + * Test handling of <code>\0</code>. + */ + @Test + public void testNullByte() throws Exception { + final IOConsoleTestUtil c = getTestUtil("Test \\0"); + c.getConsole().setHandleControlCharacters(true); + try (IOConsoleOutputStream err = c.getConsole().newOutputStream()) { + c.write("\u0000").verifyContent(""); + c.write("abc\u0000123").verifyContent("abc123"); + c.writeFast("\u0000", err).writeAndVerify("output"); + c.write("\n\u0000x\u0000y\u0000z\u0000\u0000\u0000987", err).verifyContentByLine("xyz987", 1).verifyPartitions(); + assertFalse(c.getDocument().get().contains("\u0000")); + + c.clear(); + c.writeFast("123").writeFast("\b\b\b").write("+\u0000+").verifyContent("++3").verifyPartitions(); + } + closeConsole(c); + } + + /** * Test larger number of partitions with pseudo random console content. */ @Test diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java index 6f593fe1b..0e448a6c1 100644 --- a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java @@ -98,12 +98,12 @@ public class IOConsolePartitioner * Pattern used to find supported ASCII control characters <b>except</b> * carriage return. */ - private static final String CONTROL_CHARACTERS_PATTERN_STR = "(?:\b+|\u000b+|\f+)"; //$NON-NLS-1$ + private static final String CONTROL_CHARACTERS_PATTERN_STR = "(?:\b+|\u0000+|\u000b+|\f+)"; //$NON-NLS-1$ /** * Pattern used to find supported ASCII control characters <b>including</b> * carriage return. */ - private static final String CONTROL_CHARACTERS_WITH_CR_PATTERN_STR = "(?:\b+|\u000b+|\f+|\r+(?!\n))"; //$NON-NLS-1$ + private static final String CONTROL_CHARACTERS_WITH_CR_PATTERN_STR = "(?:\b+|\u0000+|\u000b+|\f+|\r+(?!\n))"; //$NON-NLS-1$ /** The connected {@link IDocument} this partitioner manages. */ private IDocument document; @@ -881,6 +881,7 @@ public class IOConsolePartitioner applyOutputToDocument(content.toString(), nextWriteOffset, replaceLength); content.setLength(0); replaceLength = 0; + nextWriteOffset = outputOffset; final String controlCharacterMatch = controlCharacterMatcher.group(); final char controlCharacter = controlCharacterMatch.charAt(0); @@ -949,6 +950,13 @@ public class IOConsolePartitioner partititonContent(pending.stream, vtab, 0, vtab.length()); break; + case 0: + // Do nothing for null bytes. The use of this is that a null byte which reach + // the IOConsoleViewer will truncate the line on some platforms and will disturb + // copying text on most platforms. + // This case should simply filter out any null bytes. + break; + default: // should never happen as long as the used regex pattern is valid log(IStatus.ERROR, "No implementation to handle control character 0x" //$NON-NLS-1$ |