Skip to content

Commit 58260c6

Browse files
arthurscchangnodet
andauthoredAug 25, 2023
Fix invalid string input (#253)
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com> Co-authored-by: Guillaume Nodet <gnodet@gmail.com>
1 parent 7bc5862 commit 58260c6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed
 

‎src/main/java/org/fusesource/jansi/AnsiRenderer.java

+5
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ public static Appendable render(final String input, Appendable target) throws IO
9999
return target;
100100
}
101101
j += BEGIN_TOKEN_LEN;
102+
103+
// Check for invalid string with END_TOKEN before BEGIN_TOKEN
104+
if (k < j) {
105+
throw new IllegalArgumentException("Invalid input string found.");
106+
}
102107
String spec = input.substring(j, k);
103108

104109
String[] items = spec.split(CODE_TEXT_SEPARATOR, 2);

‎src/test/java/org/fusesource/jansi/AnsiRendererTest.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
import static org.fusesource.jansi.AnsiRenderer.*;
2525
import static org.junit.jupiter.api.Assertions.assertEquals;
2626
import static org.junit.jupiter.api.Assertions.assertFalse;
27+
import static org.junit.jupiter.api.Assertions.assertThrows;
2728
import static org.junit.jupiter.api.Assertions.assertTrue;
2829

2930
/**
3031
* Tests for the {@link AnsiRenderer} class.
3132
*
3233
*/
3334
public class AnsiRendererTest {
34-
3535
@BeforeAll
3636
static void setUp() {
3737
Ansi.setEnabled(true);
@@ -112,6 +112,11 @@ public void testRenderInvalidMissingEnd() {
112112
assertEquals("@|bold foo", str);
113113
}
114114

115+
@Test
116+
public void testRenderInvalidEndBeforeStart() {
117+
assertThrows(IllegalArgumentException.class, () -> render("@|@"));
118+
}
119+
115120
@Test
116121
public void testRenderInvalidMissingText() {
117122
String str = render("@|bold|@");

0 commit comments

Comments
 (0)
Please sign in to comment.