From 36f099958c1668aff753b539ff946ff9a9bc1e18 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Fri, 29 Jan 2016 15:53:58 +0100 Subject: [PATCH] Don't match @nickname on @nickname@server.com --- lib/util.php | 3 ++- plugins/OStatus/OStatusPlugin.php | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/util.php b/lib/util.php index b7eac68619..fc9b54a10e 100644 --- a/lib/util.php +++ b/lib/util.php @@ -858,7 +858,8 @@ function common_find_mentions_raw($text) PREG_OFFSET_CAPTURE); $atmatches = array(); - preg_match_all('/(?:^|\s+)@(' . Nickname::DISPLAY_FMT . ')\b/', + // the regexp's "(?!\@)" makes sure it doesn't matches the single "@remote" in "@remote@server.com" + preg_match_all('/(?:^|\s+)@(' . Nickname::DISPLAY_FMT . ')\b(?!\@)/', $text, $atmatches, PREG_OFFSET_CAPTURE); diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index af458fb40c..06aaa54ce6 100644 --- a/plugins/OStatus/OStatusPlugin.php +++ b/plugins/OStatus/OStatusPlugin.php @@ -285,8 +285,8 @@ class OStatusPlugin extends Plugin { $matches = array(); - // Webfinger matches: @user@example.com - if (preg_match_all('!(?:^|\s+)@((?:\w+\.)*\w+@(?:\w+\-?\w+\.)*\w+(?:\w+\-\w+)*\.\w+)!', + // Webfinger matches: @user@example.com or even @user--one.george_orwell@1984.biz + if (preg_match_all('!(?:^|\s+)@((?:\w+[\w\-\_\.]?)*(?:[\w\-\_\.]*\w+)@(?:\w+\-?\w+\.)*\w+(?:\w+\-\w+)*\.\w+)!', $text, $wmatches, PREG_OFFSET_CAPTURE)) { @@ -299,12 +299,16 @@ class OStatusPlugin extends Plugin $profile = $oprofile->localProfile(); $text = !empty($profile->nickname) && mb_strlen($profile->nickname) < mb_strlen($target) ? $profile->nickname : $target; + $url = $profile->getUri(); + if (!common_valid_http_url($url)) { + $url = $profile->getUrl(); + } $matches[$pos] = array('mentioned' => array($profile), 'type' => 'mention', 'text' => $text, 'position' => $pos, 'length' => mb_strlen($target), - 'url' => $profile->getUrl()); + 'url' => $url); } } catch (Exception $e) { $this->log(LOG_ERR, "Webfinger check failed: " . $e->getMessage()); -- 2.39.5