Match mentions when the username is wrapped in quotes
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
c26d847d19
commit
10ba0bed8a
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -151,7 +151,10 @@ class CommentTest extends TestCase {
|
|||
],
|
||||
[
|
||||
'@@chef is also a valid mention, no matter how strange it looks', ['@chef']
|
||||
]
|
||||
],
|
||||
[
|
||||
'Also @"user with spaces" are now supported', ['user with spaces']
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue