From 29077a2817076203d5608bf2169d5678303d54b4 Mon Sep 17 00:00:00 2001 From: mattirn Date: Wed, 29 Jan 2020 19:20:03 +0100 Subject: [PATCH] ConsoleEngineImpl: fixed StringIndexOutOfBoundsException --- .../java/org/jline/builtins/ConsoleEngineImpl.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/builtins/src/main/java/org/jline/builtins/ConsoleEngineImpl.java b/builtins/src/main/java/org/jline/builtins/ConsoleEngineImpl.java index e73d0fe42..c7524acf8 100644 --- a/builtins/src/main/java/org/jline/builtins/ConsoleEngineImpl.java +++ b/builtins/src/main/java/org/jline/builtins/ConsoleEngineImpl.java @@ -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+$", ""); @@ -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'); }