Skip to content

Commit 52d60dc

Browse files
committed
Escape $ chars in doc strings
1 parent b9d2aad commit 52d60dc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptWriter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,14 @@ TypeScriptWriter writeDocs(Runnable runnable) {
179179
/**
180180
* Writes documentation comments from a string.
181181
*
182+
* <p>This function escapes "$" characters so formatters are not run.
183+
*
182184
* @param docs Documentation to write.
183185
* @return Returns the writer.
184186
*/
185187
public TypeScriptWriter writeDocs(String docs) {
186-
writeDocs(() -> write(docs));
188+
// Docs can have valid $ characters that shouldn't run through formatters.
189+
writeDocs(() -> write(docs.replace("$", "$$")));
187190
return this;
188191
}
189192

smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/TypeScriptWriterTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ public void doesNotAddNewlineBetweenManagedAndExplicitImports() {
2525
assertThat(result, equalTo("import { Baz } from \"hello\";\nimport { Foo } from \"baz\";\n"));
2626
}
2727

28+
@Test
29+
public void escapesDollarInDocStrings() {
30+
String docs = "This is $ valid documentation.";
31+
32+
TypeScriptWriter writer = new TypeScriptWriter("foo");
33+
writer.writeDocs(docs);
34+
String result = writer.toString();
35+
36+
assertThat(result, equalTo("/**\n * " + docs + "\n */\n"));
37+
}
38+
2839
@Test
2940
public void addsFormatterForSymbols() {
3041
// TODO

0 commit comments

Comments
 (0)