Skip to content

Commit

Permalink
Merge branch 'issue-364'
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Mar 15, 2019
2 parents 886867c + b3e6ed2 commit 2a5798c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
26 changes: 14 additions & 12 deletions reader/src/main/java/org/jline/reader/impl/DefaultParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,20 @@ public ParsedLine parse(final String line, final int cursor, ParseContext contex
rawWordLength = rawWordCursor;
}

if (eofOnEscapedNewLine && isEscapeChar(line, line.length() - 1)) {
throw new EOFError(-1, -1, "Escaped new line", "newline");
}
if (eofOnUnclosedQuote && quoteStart >= 0 && context != ParseContext.COMPLETE) {
throw new EOFError(-1, -1, "Missing closing quote", line.charAt(quoteStart) == '\''
? "quote" : "dquote");
}
if (bracketChecker.isOpeningBracketMissing() && context != ParseContext.COMPLETE) {
throw new EOFError(-1, -1, "Missing opening bracket", "missing: " + bracketChecker.getMissingOpeningBracket());
}
if (bracketChecker.isClosingBracketMissing() && context != ParseContext.COMPLETE) {
throw new EOFError(-1, -1, "Missing closing brackets", "add: " + bracketChecker.getMissingClosingBrackets());
if (context != ParseContext.COMPLETE) {
if (eofOnEscapedNewLine && isEscapeChar(line, line.length() - 1)) {
throw new EOFError(-1, -1, "Escaped new line", "newline");
}
if (eofOnUnclosedQuote && quoteStart >= 0) {
throw new EOFError(-1, -1, "Missing closing quote", line.charAt(quoteStart) == '\''
? "quote" : "dquote");
}
if (bracketChecker.isOpeningBracketMissing()) {
throw new EOFError(-1, -1, "Missing opening bracket", "missing: " + bracketChecker.getMissingOpeningBracket());
}
if (bracketChecker.isClosingBracketMissing()) {
throw new EOFError(-1, -1, "Missing closing brackets", "add: " + bracketChecker.getMissingClosingBrackets());
}
}

String openingQuote = quotedWord ? line.substring(quoteStart, quoteStart + 1) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,12 @@ public void testDumbTerminalNoSizeComplete() {
assertLine("a", new TestBuffer("a\t\n\n"));
}

@Test
public void testParserEofOnEscapedNewLine() {
DefaultParser parser = new DefaultParser();
parser.setEofOnEscapedNewLine(true);
reader.setParser(parser);

assertLine("test ", new TestBuffer("test \\\t\n\n"));
}
}

0 comments on commit 2a5798c

Please sign in to comment.