diff options
-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$ |