Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

Commit 9c5782e

Browse files
Escape docstrings (#57)
1 parent 271890d commit 9c5782e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/betterproto2_compiler/plugin/models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,12 @@ def get_comment(
129129
# We don't add this space to the generated file.
130130
lines = [line[1:] if line and line[0] == " " else line for line in lines]
131131

132-
return "\n".join(lines)
132+
comment = "\n".join(lines)
133+
134+
# Escape backslashes and triple quotes
135+
comment = comment.replace("\\", "\\\\").replace('"""', '\\"\\"\\"')
136+
137+
return comment
133138

134139
return ""
135140

tests/inputs/documentation/documentation.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@ service Service { // Documentation of service 3
5656
// other line 2
5757
rpc get(Test) returns (Test); // Documentation of method 3
5858
}
59+
60+
// A comment with backslashes \ and triple quotes """
61+
// Simple quotes are not escaped "
62+
message ComplexDocumentation {}

0 commit comments

Comments
 (0)