Skip to content

Commit c3ac54f

Browse files
arthurscchangnodet
andauthoredAug 25, 2023
Fix infinite loop bug (#252)
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com> Co-authored-by: Guillaume Nodet <gnodet@gmail.com>
1 parent 58260c6 commit c3ac54f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
 

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

+6
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,16 @@ public Ansi eraseLine(final Erase kind) {
703703
}
704704

705705
public Ansi scrollUp(final int rows) {
706+
if (rows == Integer.MIN_VALUE) {
707+
return scrollDown(Integer.MAX_VALUE);
708+
}
706709
return rows > 0 ? appendEscapeSequence('S', rows) : rows < 0 ? scrollDown(-rows) : this;
707710
}
708711

709712
public Ansi scrollDown(final int rows) {
713+
if (rows == Integer.MIN_VALUE) {
714+
return scrollUp(Integer.MAX_VALUE);
715+
}
710716
return rows > 0 ? appendEscapeSequence('T', rows) : rows < 0 ? scrollUp(-rows) : this;
711717
}
712718

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

+18
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ public void apply(Ansi ansi) {
6767
.toString());
6868
}
6969

70+
@ParameterizedTest
71+
@CsvSource({
72+
"-2147483648,ESC[2147483647T", "2147483647,ESC[2147483647S",
73+
"-100000,ESC[100000T", "100000,ESC[100000S"
74+
})
75+
public void testScrollUp(int x, String expected) {
76+
assertAnsi(expected, Ansi.ansi().scrollUp(x));
77+
}
78+
79+
@ParameterizedTest
80+
@CsvSource({
81+
"-2147483648,ESC[2147483647S", "2147483647,ESC[2147483647T",
82+
"-100000,ESC[100000S", "100000,ESC[100000T"
83+
})
84+
public void testScrollDown(int x, String expected) {
85+
assertAnsi(expected, Ansi.ansi().scrollDown(x));
86+
}
87+
7088
@ParameterizedTest
7189
@CsvSource({
7290
"-1,-1,ESC[1;1H", "-1,0,ESC[1;1H", "-1,1,ESC[1;1H", "-1,2,ESC[1;2H",

0 commit comments

Comments
 (0)
Please sign in to comment.