]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Don't match @nickname on @nickname@server.com
authorMikael Nordfeldth <mmn@hethane.se>
Fri, 29 Jan 2016 14:53:58 +0000 (15:53 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Fri, 29 Jan 2016 14:53:58 +0000 (15:53 +0100)
lib/util.php
plugins/OStatus/OStatusPlugin.php

index b7eac68619c16ade5cb2d9ba80130d0f1b0a3c12..fc9b54a10eaae6500736155e883baa6f6a7cba51 100644 (file)
@@ -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);
index af458fb40cc69a79973e1a4049abaa85a8d023e3..06aaa54ce6a1764378a591ebeb80b84c31064364 100644 (file)
@@ -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());