Skip to content

Commit 27b49d9

Browse files
Chase Coalwellkstich
authored andcommitted
Escape multi-line comment close tag in docs (#77)
1 parent eff63bf commit 27b49d9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ TypeScriptWriter writeDocs(Runnable runnable) {
189189
*/
190190
public TypeScriptWriter writeDocs(String docs) {
191191
// Docs can have valid $ characters that shouldn't run through formatters.
192-
writeDocs(() -> write(docs.replace("$", "$$")));
192+
// Escapes multi-line comment closings.
193+
writeDocs(() -> write(docs.replace("$", "$$").replace("*/", "*\\/")));
193194
return this;
194195
}
195196

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
@@ -36,6 +36,17 @@ public void escapesDollarInDocStrings() {
3636
assertThat(result, equalTo("/**\n * " + docs + "\n */\n"));
3737
}
3838

39+
@Test
40+
public void escapesMultiLineCloseInDocStrings() {
41+
String docs = "This is */ valid documentation.";
42+
43+
TypeScriptWriter writer = new TypeScriptWriter("foo");
44+
writer.writeDocs(docs);
45+
String result = writer.toString();
46+
47+
assertThat(result, equalTo("/**\n * This is *\\/ valid documentation.\n */\n"));
48+
}
49+
3950
@Test
4051
public void addsFormatterForSymbols() {
4152
// TODO

0 commit comments

Comments
 (0)