Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NXP-30533: Fix text expansion of default values #4892

Merged
merged 1 commit into from Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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