Skip to content

Commit

Permalink
Exception when parsing infocmp number "0", fixes #451
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Oct 25, 2019
1 parent 6116228 commit 68234fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion terminal/src/main/java/org/jline/utils/InfoCmp.java
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,9 @@ public static void parseInfoCmp(
String key = cap.substring(0, index);
String val = cap.substring(index + 1);
int iVal;
if (val.startsWith("0x")) {
if ("0".equals(val)) {
iVal = 0;
} else if (val.startsWith("0x")) {
iVal = Integer.parseInt(val.substring(2), 16);
} else if (val.startsWith("0")) {
iVal = Integer.parseInt(val.substring(1), 8);
Expand Down
3 changes: 2 additions & 1 deletion terminal/src/test/java/org/jline/utils/InfoCmpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ public void testInfoCmpWithHexa() {
Map<Capability, String> strings = new HashMap<>();
String infocmp = "xterm-256color|xterm with 256 colors,\n" +
"\tam, bce, ccc, km, mc5i, mir, msgr, npc, xenl,\n" +
"\tcolors#0x100, cols#80, it#8, lines#24, pairs#0x7fff,\n" +
"\tcolors#0x100, cols#010, it#0, lines#24, pairs#0x7fff,\n" +
"\tacsc=``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,\n" +
"\tbel=^G, blink=\\E[5m, bold=\\E[1m, cbt=\\E[Z, civis=\\E[?25l\n";
InfoCmp.parseInfoCmp(infocmp, bools, ints, strings);
assertEquals(8, (int) ints.get(Capability.columns));
assertEquals(0x100, (int) ints.get(Capability.max_colors));
assertEquals(0x7fff, (int) ints.get(Capability.max_pairs));
}
Expand Down

0 comments on commit 68234fc

Please sign in to comment.