Skip to content

Commit 44175e3

Browse files
Merge pull request nextcloud#58998 from nextcloud/bugfix/noid/dont-count-mentions-in-markdown-code
fix(comments): Correctly treat end of message as end of code block/in…
2 parents 1b504bf + fe89541 commit 44175e3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/private/Comments/Comment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function getMentions(bool $supportMarkdown = true): array {
198198
$message = $this->getMessage();
199199
if ($supportMarkdown) {
200200
// Strip fenced code blocks and inline code so mentions inside them are ignored
201-
$message = preg_replace('/^```.*?^```|^~~~.*?^~~~/sm', '', $message);
201+
$message = preg_replace('/^```.*?(^```|\z)|^~~~.*?(^~~~|\z)/sm', '', $message);
202202
$message = preg_replace('/`[^`\n]*`/', '', $message);
203203
}
204204

tests/lib/Comments/CommentTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,18 @@ public static function mentionsProvider(): array {
240240
null,
241241
false,
242242
],
243+
[
244+
'Mention @alice and `also @bob as end of text only applies to code blocks',
245+
[['type' => 'user', 'id' => 'alice'], ['type' => 'user', 'id' => 'bob']],
246+
],
247+
[
248+
"Mention @alice but not in unclosed fenced code block\n```\n@bob\n@charlie",
249+
[['type' => 'user', 'id' => 'alice']],
250+
],
251+
[
252+
"Mention @alice but not in unclosed tilde code block\n~~~\n@bob",
253+
[['type' => 'user', 'id' => 'alice']],
254+
],
243255
];
244256
}
245257

0 commit comments

Comments
 (0)