diff options
author | Joas Schilling <coding@schilljs.com> | 2021-01-29 11:46:14 +0300 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2021-02-06 15:07:05 +0300 |
commit | 1344c61145c2a9eb36c1c211daa9018f00693c7c (patch) | |
tree | 46d58bd955a8acb92680319c449b4e3bcbf7d82e /apps/comments/lib | |
parent | 6945bd8cc388a7a697ef0342d406423f2e545a78 (diff) |
Improve mention matches
The previous regex didn't correctly match users with . ' or -
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/comments/lib')
-rw-r--r-- | apps/comments/lib/Activity/Provider.php | 12 | ||||
-rw-r--r-- | apps/comments/lib/Notification/Notifier.php | 6 |
2 files changed, 8 insertions, 10 deletions
diff --git a/apps/comments/lib/Activity/Provider.php b/apps/comments/lib/Activity/Provider.php index 527c9c4ca69..fca3b9e75d5 100644 --- a/apps/comments/lib/Activity/Provider.php +++ b/apps/comments/lib/Activity/Provider.php @@ -213,17 +213,11 @@ class Provider implements IProvider { continue; } - $pattern = '/(^|\s)(' . '@' . $mention['id'] . ')(\b)/'; - if (strpos($mention['id'], ' ') !== false) { - $pattern = '/(^|\s)(' . '@"' . $mention['id'] . '"' . ')(\b)?/'; + $message = str_replace('@"' . $mention['id'] . '"', '{mention' . $mentionCount . '}', $message); + if (strpos($mention['id'], ' ') === false && strpos($mention['id'], 'guest/') !== 0) { + $message = str_replace('@' . $mention['id'], '{mention' . $mentionCount . '}', $message); } - $message = preg_replace( - $pattern, - //'${1}' . $this->regexSafeUser($mention['id'], $displayName) . '${3}', - '${1}' . '{mention' . $mentionCount . '}' . '${3}', - $message - ); $mentions['mention' . $mentionCount] = $this->generateUserParameter($mention['id']); $mentionCount++; } diff --git a/apps/comments/lib/Notification/Notifier.php b/apps/comments/lib/Notification/Notifier.php index 9f69e5599f8..20e0667d143 100644 --- a/apps/comments/lib/Notification/Notifier.php +++ b/apps/comments/lib/Notification/Notifier.php @@ -195,7 +195,11 @@ class Notifier implements INotifier { // could contain characters like '@' for user IDs) but a one-based // index of the mentions of that type. $mentionParameterId = 'mention-' . $mention['type'] . $mentionTypeCount[$mention['type']]; - $message = str_replace('@' . $mention['id'], '{' . $mentionParameterId . '}', $message); + $message = str_replace('@"' . $mention['id'] . '"', '{' . $mentionParameterId . '}', $message); + if (strpos($mention['id'], ' ') === false && strpos($mention['id'], 'guest/') !== 0) { + $message = str_replace('@' . $mention['id'], '{' . $mentionParameterId . '}', $message); + } + try { $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']); } catch (\OutOfBoundsException $e) { |