Skip to content
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
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"));
}
}