Skip to content

Commit

Permalink
i-search crashes with default setup, fixes #58
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Dec 9, 2016
1 parent 65d06a0 commit d6ac0de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/jline/reader/impl/LineReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2193,6 +2193,10 @@ protected boolean historyIncrementalSearchBackward() {
}

protected boolean doSearchHistory(boolean backward) {
if (history.isEmpty()) {
return false;
}

BufferImpl originalBuffer = buf.copy();
String previousSearchTerm = (searchTerm != null) ? searchTerm.toString() : "";
searchTerm = new StringBuffer(buf.toString());
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/jline/reader/impl/HistorySearchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,15 @@ public void testAbortingAfterSearchingPreviousLinesGivesBlank() throws Exception
assertEquals("", reader.getBuffer().toString());
assertEquals(3, history.size());
}

@Test
public void testSearchOnEmptyHistory() throws Exception {
DefaultHistory history = setupHistory();
history.purge();

String readLineResult;
in.setIn(new ByteArrayInputStream(translate("^Sa").getBytes()));
readLineResult = reader.readLine();
assertEquals(null, readLineResult);
}
}

0 comments on commit d6ac0de

Please sign in to comment.