Skip to content

Commit

Permalink
REPL parameter expansion, do not add quote chars on numeric parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Apr 5, 2020
1 parent 5438565 commit 88c28ae
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions builtins/src/main/java/org/jline/builtins/ConsoleEngineImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,15 @@ public boolean execute() throws Exception {
return true;
}

private String expandParameterName(String parameter) {
if (parameter.startsWith("$")) {
return expandName(parameter);
} else if (isNumber(parameter)) {
return parameter;
}
return quote(parameter);
}

private void internalExecute() throws Exception {
if (isEngineScript()) {
result = engine.execute(script, expandParameters(args));
Expand All @@ -584,18 +593,17 @@ private void internalExecute() throws Exception {
done = true;
for (int i = 1; i < args.length; i++) {
line = line.replaceAll("\\s\\$" + i + "\\b",
args[i].startsWith("$") ? (" " + expandName(args[i]) + " ")
: (" " + quote(args[i]) + " "));
(" " + expandParameterName(args[i]) + " "));
line = line.replaceAll("\\$\\{" + i + "(|:-.*)\\}",
args[i].startsWith("$") ? expandName(args[i]) : quote(args[i]));
expandParameterName(args[i]));
}
line = line.replaceAll("\\$\\{@\\}", expandToList(args));
line = line.replaceAll("\\$@", expandToList(args));
line = line.replaceAll("\\s\\$\\d\\b", "");
line = line.replaceAll("\\$\\{\\d+\\}", "");
Matcher matcher = Pattern.compile("\\$\\{\\d+:-(.*?)\\}").matcher(line);
if (matcher.find()) {
line = matcher.replaceAll("'$1'");
line = matcher.replaceAll(expandParameterName(matcher.group(1)));
}
if (verbose) {
AttributedStringBuilder asb = new AttributedStringBuilder();
Expand Down

0 comments on commit 88c28ae

Please sign in to comment.