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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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']],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user