Skip to content

Commit dc452ae

Browse files
committed
fix: improve escaping of backticks in github issue comments
1 parent 32b872f commit dc452ae

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/shared/github.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,28 @@ def affected_nix_packages() -> str:
108108

109109
def additional_comment() -> str:
110110
if comment:
111-
escaped_comment = comment.replace("`", "\\`")
111+
# Find the maximum number of consecutive backticks in the comment
112+
max_backticks = 0
113+
current_backticks = 0
114+
115+
for char in comment:
116+
if char == "`":
117+
current_backticks += 1
118+
max_backticks = max(max_backticks, current_backticks)
119+
else:
120+
current_backticks = 0
121+
122+
# Use at least 3 backticks, or one more than the maximum found in
123+
# order to escape accidents or attempts at escaping the code block
124+
fence_backticks = "`" * max(3, max_backticks + 1)
125+
112126
return f"""
113127
114128
## Additional comment
115129
116-
```
117-
{escaped_comment}
118-
```"""
130+
{fence_backticks}
131+
{comment}
132+
{fence_backticks}"""
119133
else:
120134
return ""
121135

0 commit comments

Comments
 (0)