Skip to content

Commit

Permalink
ConsoleEngineImpl: fixed StringIndexOutOfBoundsException
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Jan 29, 2020
1 parent 33dad4a commit 29077a2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions builtins/src/main/java/org/jline/builtins/ConsoleEngineImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ public boolean execute() throws Exception {
int size = 0;
StringBuilder usage = new StringBuilder();
boolean helpEnd = false;
boolean headComment = false;
for(String l; (l = br.readLine()) != null; ) {
size++;
l = l.replaceAll("\\s+$", "");
Expand All @@ -409,10 +410,15 @@ public boolean execute() throws Exception {
helpEnd = line.endsWith(END_HELP);
break;
}
if (l.trim().startsWith("*") || l.trim().startsWith("#")) {
line = l.trim().substring(2);
} else if (l.trim().startsWith("/*") || l.trim().startsWith("//")) {
line = l.trim().substring(3);
if (headComment || size < 3) {
String ltr = l.trim();
if (ltr.startsWith("*") || ltr.startsWith("#")) {
headComment = true;
line = ltr.length() > 1 ? ltr.substring(2) : "";
} else if (ltr.startsWith("/*") || ltr.startsWith("//")) {
headComment = true;
line = ltr.length() > 2 ? ltr.substring(3) : "";
}
}
usage.append(line).append('\n');
}
Expand Down

0 comments on commit 29077a2

Please sign in to comment.