Skip to content

Commit

Permalink
#676 interpolated string should resolve to null if no value found and…
Browse files Browse the repository at this point in the history
… variable has no other text
  • Loading branch information
remkop authored May 2, 2019
1 parent 3e21fcb commit 8eafa1e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ public void clearExecutionResults() {
* @see RunFirst
* @see RunLast
* @see RunAll
* @deprecated use {@link IParameterExceptionHandler} instead, see {@link #execute(String...)}
* @deprecated use {@link IExecutionStrategy} instead, see {@link #execute(String...)}
* @since 3.0 */
@Deprecated public static interface IParseResultHandler2<R> {
/** Processes the {@code ParseResult} object resulting from successfully
Expand Down Expand Up @@ -8832,11 +8832,11 @@ private String resolveLookups(String text, Set<String> visited, Map<String, Stri
for (String lookupKey : lookups.keySet()) {
ILookup lookup = lookups.get(lookupKey);
String prefix = "${" + lookupKey;
int sysStartPos = 0;
while ((sysStartPos = findOpeningDollar(text, prefix, sysStartPos)) >= 0) {
int endPos = findClosingBrace(text, sysStartPos + prefix.length());
int startPos = 0;
while ((startPos = findOpeningDollar(text, prefix, startPos)) >= 0) {
int endPos = findClosingBrace(text, startPos + prefix.length());
if (endPos < 0) { endPos = text.length() - 1; }
String fullKey = text.substring(sysStartPos + prefix.length(), endPos);
String fullKey = text.substring(startPos + prefix.length(), endPos);
String actualKey = fullKey;

int defaultStartPos = fullKey.indexOf(":-");
Expand All @@ -8852,10 +8852,13 @@ private String resolveLookups(String text, Set<String> visited, Map<String, Stri
value = resolveLookups(defaultValue, visited, resolved);
}
resolved.put(prefix + actualKey, value);
if (value == null && startPos == 0 && endPos == text.length() - 1) {
return null;
}

// interpolate
text = text.substring(0, sysStartPos) + value + text.substring(endPos + 1);
sysStartPos += value == null ? "null".length() : value.length();
text = text.substring(0, startPos) + value + text.substring(endPos + 1);
startPos += value == null ? "null".length() : value.length();
}
}
return text.replace("$$", "$");
Expand Down

0 comments on commit 8eafa1e

Please sign in to comment.