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

Escape popped state content #187

Merged
merged 1 commit into from
Oct 14, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Escape popped state content
The contents of captured named states needs to be escaped when writing
it to ensure that any "$" signs that may have been escaped or expanded
in the original content are passed through as-is.
  • Loading branch information
mtdowling committed Oct 13, 2019
commit 07c0839ecec4de8492843b8d9ab7f4b1b7f2c056
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,8 @@ public CodeWriter popState() {
} else {
// Sections can be added that are just placeholders. In those cases,
// do not write anything unless the section emitted a non-empty string.
writeOptional(result);
// Note that this has already been formatted, so escape "$".
writeOptional(result.replace("$", "$$"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,12 @@ public void hasOpenBlockRunnable5() {

assertThat(result, equalTo("public 1 2 3 4 5 {\n hi();\n}\n"));
}

@Test
public void poppedSectionsEscapeDollars() {
CodeWriter writer = CodeWriter.createDefault();
String result = writer.pushState("foo").write("$$Hello").popState().toString();

assertThat(result, equalTo("$Hello\n"));
}
}