Skip to content

Commit

Permalink
Expand parameter in file path, fixes #516
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Mar 13, 2020
1 parent 02c7f67 commit 07b2df9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions builtins/src/main/java/org/jline/builtins/ConsoleEngineImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,16 @@ public Map<String, Boolean> scripts() {
@Override
public Object[] expandParameters(String[] args) throws Exception {
Object[] out = new Object[args.length];
String regexPath = "(.*)\\$\\{(.*?)\\}(/.*)";
for (int i = 0; i < args.length; i++) {
if (args[i].startsWith("${")) {
if (args[i].matches(regexPath)) {
Matcher matcher = Pattern.compile(regexPath).matcher(args[i]);
if (matcher.find()) {
out[i] = matcher.group(1) + (String)engine.get(matcher.group(2)) + matcher.group(3);
} else {
throw new IllegalArgumentException();
}
} else if (args[i].startsWith("${")) {
out[i] = engine.execute(expandName(args[i]));
} else if (args[i].startsWith("$")) {
out[i] = engine.get(expandName(args[i]));
Expand Down Expand Up @@ -536,7 +544,7 @@ private void internalExecute() throws Exception {
line = line.replaceAll("\\$@", expandToList(args));
line = line.replaceAll("\\s\\$\\d\\b", "");
line = line.replaceAll("\\$\\{\\d+\\}", "");
Matcher matcher=Pattern.compile("\\$\\{\\d+:-(.*?)\\}").matcher(line);
Matcher matcher = Pattern.compile("\\$\\{\\d+:-(.*?)\\}").matcher(line);
if (matcher.find()) {
line = matcher.replaceAll("'$1'");
}
Expand Down

0 comments on commit 07b2df9

Please sign in to comment.