Skip to content

Commit

Permalink
NXP-30533: Fix text expansion of default values
Browse files Browse the repository at this point in the history
  • Loading branch information
efge committed Jul 26, 2021
1 parent b954490 commit 75e3d3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Expand Up @@ -103,7 +103,9 @@ public class TextTemplate {
*/
private static final Pattern PATTERN = Pattern.compile("(?<!\\$)\\$\\{(?<" + PATTERN_GROUP_DECRYPT + ">#)?" //
+ "(?<" + PATTERN_GROUP_VAR + ">[a-zA-Z_0-9\\-\\.]+)" // embeddedVar
+ "(:=(?<" + PATTERN_GROUP_DEFAULT + ">.*))?\\}"); // defaultValue
+ "(:=(?<" + PATTERN_GROUP_DEFAULT + ">" // defaultValue
+ "([^{}]*|\\{[^{}]*\\})" // no braces or one balanced set
+ "))?\\}");

private final CryptoProperties vars;

Expand Down
Expand Up @@ -146,6 +146,13 @@ public void testParameterExpansion() {
assertEquals("<foo></foo>", tt.processText("<foo>${myUnresolvedExpression}</foo>"));
}

@Test
public void testParameterExpansionExtraBrace() {
TextTemplate tt = new TextTemplate();
// check behavior when there's another closing brace further in the line
assertEquals("deffoo bar}", tt.processText("${foo:=deffoo} bar}"));
}

@Test
public void testEscapeVariable() {
TextTemplate templates = new TextTemplate();
Expand Down

0 comments on commit 75e3d3e

Please sign in to comment.