fix lost text tail when text ends with incomplete escape sequence

Bug occurred when text ends with \u001B' char (without following '[')
This commit is contained in:
Sergey Simonchik
2017-10-04 02:39:55 +03:00
parent 24553631cf
commit daaa6e228e
2 changed files with 10 additions and 3 deletions
@@ -63,6 +63,9 @@ public class AnsiEscapeDecoder {
if (escSeqBeginInd < -1) {
unhandledSuffixLength = decodeUnhandledSuffixLength(escSeqBeginInd);
}
if (pos < text.length() - unhandledSuffixLength) {
chunks = processTextChunk(chunks, text.substring(pos, text.length() - unhandledSuffixLength), outputType, textAcceptor);
}
break;
}
if (pos < escSeqBeginInd) {
@@ -91,9 +94,6 @@ public class AnsiEscapeDecoder {
pos = escSeqEndInd + 1;
}
updateUnhandledSuffix(text, outputType, unhandledSuffixLength);
if (unhandledSuffixLength == 0 && pos < text.length()) {
chunks = processTextChunk(chunks, text.substring(pos), outputType, textAcceptor);
}
if (chunks != null && textAcceptor instanceof ColoredChunksAcceptor) {
((ColoredChunksAcceptor)textAcceptor).coloredChunksAvailable(chunks);
}
@@ -84,6 +84,13 @@ public class AnsiEscapeDecoderTest extends PlatformTestCase {
.addExpected(":abcd", "\u001B[1;33m")
.addExpected(">", "\u001B[0;1;33m")
));
check(false, ContainerUtil.newArrayList(
new ColoredText("\u001B[1;31m red\u001B[0m normal\u001B[1;32m green\u001B", ProcessOutputTypes.STDOUT)
.addExpected(" red", "\u001B[1;31m")
.addExpected(" normal", STDOUT_KEY)
.addExpected(" green", "\u001B[1;32m"),
new ColoredText("[0m\n", ProcessOutputTypes.STDOUT).addExpected("\n", STDOUT_KEY)
));
}
public void testStderr() {