From fe89541be33d6d58bf7e7360d207e4501c948b8b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 17 Mar 2026 12:49:32 +0100 Subject: [PATCH] fix(comments): Correctly treat end of message as end of code block/inline Signed-off-by: Joas Schilling --- lib/private/Comments/Comment.php | 2 +- tests/lib/Comments/CommentTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php index 551b9d29e29d0..7d2d861e8b4ce 100644 --- a/lib/private/Comments/Comment.php +++ b/lib/private/Comments/Comment.php @@ -198,7 +198,7 @@ public function getMentions(bool $supportMarkdown = true): array { $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); } diff --git a/tests/lib/Comments/CommentTest.php b/tests/lib/Comments/CommentTest.php index 67d84d4ddbe9b..80bc5d7818fce 100644 --- a/tests/lib/Comments/CommentTest.php +++ b/tests/lib/Comments/CommentTest.php @@ -240,6 +240,18 @@ public static function mentionsProvider(): array { 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']], + ], ]; }