Skip to content

Commit

Permalink
Less fails when a bad regex pattern is used, fixes #304
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Aug 27, 2018
1 parent d18b65c commit 4b8a571
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions builtins/src/main/java/org/jline/builtins/Less.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Map;
import java.util.TreeMap;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import org.jline.keymap.BindingReader;
import org.jline.keymap.KeyMap;
Expand Down Expand Up @@ -217,13 +218,27 @@ else if (buffer.length() > 0 && (buffer.charAt(0) == '/' || buffer.charAt(0) ==
int c = terminal.reader().read();
message = null;
if (c == '\r') {
pattern = buffer.toString().substring(1);
if (buffer.charAt(0) == '/') {
moveToNextMatch();
} else {
moveToPreviousMatch();
try {
pattern = buffer.toString().substring(1);
getPattern();
if (buffer.charAt(0) == '/') {
moveToNextMatch();
} else {
moveToPreviousMatch();
}
buffer.setLength(0);
} catch (PatternSyntaxException e) {
String str = e.getMessage();
if (str.indexOf('\n') > 0) {
str = str.substring(0, str.indexOf('\n'));
}
pattern = null;
buffer.setLength(0);
message = "Invalid pattern: " + str + " (Press a key)";
display(false);
terminal.reader().read();
message = null;
}
buffer.setLength(0);
} else {
buffer.append((char) c);
}
Expand Down

0 comments on commit 4b8a571

Please sign in to comment.