Skip to content

Commit

Permalink
fix: escapes $$ prior to escaping \$
Browse files Browse the repository at this point in the history
closes: #1056

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
  • Loading branch information
shawkins committed Dec 4, 2023
1 parent 5a96de2 commit 889fa9f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,18 @@ public void accept(ResolveContext<RuntimeException> resolveContext, StringBuilde
* dollar.
*/
private String escapeDollarIfExists(final String value) {
int index = value.indexOf("\\$");
return escapeIfExists(escapeIfExists(value, "$$", "$$$$"), "\\$", "$$");
}

private String escapeIfExists(final String value, final String toEscape, final String escaped) {
int index = value.indexOf(toEscape);
if (index != -1) {
int start = 0;
StringBuilder builder = new StringBuilder();
while (index != -1) {
builder.append(value, start, index).append("$$");
start = index + 2;
index = value.indexOf("\\$", start);
builder.append(value, start, index).append(escaped);
start = index + toEscape.length();
index = value.indexOf(toEscape, start);
}
builder.append(value.substring(start));
return builder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ void withoutExpansion() {

@Test
void escape() {
assertEquals("${my.prop}", buildConfig("expression", "$${my.prop}").getRawValue("expression"));
assertEquals("$${my.prop}", buildConfig("expression", "$${my.prop}").getRawValue("expression"));
assertEquals("${my.prop}", buildConfig("expression", "\\${my.prop}").getRawValue("expression"));

assertEquals("file:target/prices/?fileName=${date:now:yyyyMMddssSS}.txt&charset=utf-8",
assertEquals("file:target/prices/?fileName=$${date:now:yyyyMMddssSS}.txt&charset=utf-8",
buildConfig("camel.expression",
"file:target/prices/?fileName=$${date:now:yyyyMMddssSS}.txt&charset=utf-8")
.getRawValue("camel.expression"));
Expand Down

0 comments on commit 889fa9f

Please sign in to comment.