Merge pull request #11836 from nextcloud/bugfix/2443/comment-mentions-with-spaces
Comment mentions with spaces
This commit is contained in:
commit
ab3543380c
4 changed files with 13 additions and 5 deletions
Binary file not shown.
|
@ -213,8 +213,13 @@ class Provider implements IProvider {
|
|||
continue;
|
||||
}
|
||||
|
||||
$pattern = '/(^|\s)(' . '@' . $mention['id'] . ')(\b)/';
|
||||
if (strpos($mention['id'], ' ') !== false) {
|
||||
$pattern = '/(^|\s)(' . '@"' . $mention['id'] . '"' . ')(\b)?/';
|
||||
}
|
||||
|
||||
$message = preg_replace(
|
||||
'/(^|\s)(' . '@' . $mention['id'] . ')(\b)/',
|
||||
$pattern,
|
||||
//'${1}' . $this->regexSafeUser($mention['id'], $displayName) . '${3}',
|
||||
'${1}' . '{mention' . $mentionCount . '}' . '${3}',
|
||||
$message
|
||||
|
|
|
@ -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…
Reference in a new issue