Skip to content

Commit

Permalink
Merge branch 'mattirn-master'
Browse files Browse the repository at this point in the history
# Veuillez entrer un message de validation pour expliquer en quoi cette fusion est
# nécessaire, surtout si cela fusionne une branche amont mise à jour dans une branche de sujet.
#
# Les lignes commençant par '#' seront ignorées, et un message vide
# abandonne la validation.
  • Loading branch information
gnodet committed Nov 13, 2018
2 parents f85da18 + 8ae798f commit dc97839
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
30 changes: 16 additions & 14 deletions reader/src/main/java/org/jline/reader/impl/DefaultParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,20 +373,22 @@ public String line() {
public CharSequence escape(CharSequence candidate, boolean complete) {
StringBuilder sb = new StringBuilder(candidate);
Predicate<Integer> needToBeEscaped;
// Completion is protected by an opening quote:
// Delimiters (spaces) don't need to be escaped, nor do other quotes, but everything else does.
// Also, close the quote at the end
if (openingQuote != null) {
needToBeEscaped = i -> isRawEscapeChar(sb.charAt(i)) || String.valueOf(sb.charAt(i)).equals(openingQuote);
}
// No quote protection, need to escape everything: delimiter chars (spaces), quote chars
// and escapes themselves
else {
needToBeEscaped = i -> isDelimiterChar(sb, i) || isRawEscapeChar(sb.charAt(i)) || isRawQuoteChar(sb.charAt(i));
}
for (int i = 0; i < sb.length(); i++) {
if (needToBeEscaped.test(i)) {
sb.insert(i++, escapeChars[0]);
if (escapeChars != null) {
// Completion is protected by an opening quote:
// Delimiters (spaces) don't need to be escaped, nor do other quotes, but everything else does.
// Also, close the quote at the end
if (openingQuote != null) {
needToBeEscaped = i -> isRawEscapeChar(sb.charAt(i)) || String.valueOf(sb.charAt(i)).equals(openingQuote);
}
// No quote protection, need to escape everything: delimiter chars (spaces), quote chars
// and escapes themselves
else {
needToBeEscaped = i -> isDelimiterChar(sb, i) || isRawEscapeChar(sb.charAt(i)) || isRawQuoteChar(sb.charAt(i));
}
for (int i = 0; i < sb.length(); i++) {
if (needToBeEscaped.test(i)) {
sb.insert(i++, escapeChars[0]);
}
}
}
if (openingQuote != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
package org.jline.reader.completer;

import org.jline.reader.impl.DefaultParser;
import org.jline.reader.impl.ReaderTestSupport;
import org.jline.reader.impl.completer.StringsCompleter;
import org.junit.Test;
Expand All @@ -30,4 +31,16 @@ public void test1() throws Exception {
assertBuffer("ba", new TestBuffer("ba").tab());
assertBuffer("baz ", new TestBuffer("baz").tab());
}

@Test
public void escapeCharsNull() throws Exception {
DefaultParser dp = (DefaultParser)reader.getParser();
dp.setEscapeChars(null);
reader.setParser(dp);
reader.setCompleter(new StringsCompleter("foo bar", "bar"));

assertBuffer("foo bar ", new TestBuffer("f").tab());
assertBuffer("bar ", new TestBuffer("b").tab());
}

}

0 comments on commit dc97839

Please sign in to comment.