Match mentions when the username is wrapped in quotes

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/11836/head
Joas Schilling 6 years ago
parent c26d847d19
commit 10ba0bed8a
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA

@ -225,14 +225,14 @@ class Comment implements IComment {
*
*/
public function getMentions() {
$ok = preg_match_all("/\B(?<![^a-z0-9_\-@\.\'\s])@[a-z0-9_\-@\.\']+/i", $this->getMessage(), $mentions);
$ok = preg_match_all("/\B(?<![^a-z0-9_\-@\.\'\s])@(\"[a-z0-9_\-@\.\' ]+\"|[a-z0-9_\-@\.\']+)/i", $this->getMessage(), $mentions);
if(!$ok || !isset($mentions[0]) || !is_array($mentions[0])) {
return [];
}
$uids = array_unique($mentions[0]);
$result = [];
foreach ($uids as $uid) {
$result[] = ['type' => 'user', 'id' => substr($uid, 1)];
$result[] = ['type' => 'user', 'id' => trim(substr($uid, 1), '"')];
}
return $result;
}

@ -150,8 +150,11 @@ class CommentTest extends TestCase {
['foobar', 'barfoo', 'foo@bar.com', 'bar@foo.org@foobar.io', '23452-4333-54353-2342', 'yolo']
],
[
'@@chef is also a valid mention, no matter how strange it looks', ['@chef']
]
'@@chef is also a valid mention, no matter how strange it looks', ['@chef']
],
[
'Also @"user with spaces" are now supported', ['user with spaces']
],
];
}

Loading…
Cancel
Save