fix(comments): Correctly treat end of message as end of code block/inline

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2026-03-17 12:49:32 +01:00 committed by Anna
parent f8652506ac
commit e305bab73f
2 changed files with 13 additions and 1 deletions

View file

@ -198,7 +198,7 @@ class Comment implements IComment {
$message = $this->getMessage();
if ($supportMarkdown) {
// Strip fenced code blocks and inline code so mentions inside them are ignored
$message = preg_replace('/^```.*?^```|^~~~.*?^~~~/sm', '', $message);
$message = preg_replace('/^```.*?(^```|\z)|^~~~.*?(^~~~|\z)/sm', '', $message);
$message = preg_replace('/`[^`\n]*`/', '', $message);
}

View file

@ -240,6 +240,18 @@ class CommentTest extends TestCase {
null,
false,
],
[
'Mention @alice and `also @bob as end of text only applies to code blocks',
[['type' => 'user', 'id' => 'alice'], ['type' => 'user', 'id' => 'bob']],
],
[
"Mention @alice but not in unclosed fenced code block\n```\n@bob\n@charlie",
[['type' => 'user', 'id' => 'alice']],
],
[
"Mention @alice but not in unclosed tilde code block\n~~~\n@bob",
[['type' => 'user', 'id' => 'alice']],
],
];
}