Daniel Supernault преди 6 години
родител
ревизия
7260ca2100
променени са 3 файла, в които са добавени 15 реда и са изтрити 4 реда
  1. 8 2
      app/Util/Lexer/Autolink.php
  2. 4 1
      app/Util/Lexer/Extractor.php
  3. 3 1
      app/Util/Lexer/Regex.php

+ 8 - 2
app/Util/Lexer/Autolink.php

@@ -9,6 +9,8 @@
 
 
 namespace App\Util\Lexer;
 namespace App\Util\Lexer;
 
 
+use Illuminate\Support\Str;
+
 /**
 /**
  * Twitter Autolink Class.
  * Twitter Autolink Class.
  *
  *
@@ -413,7 +415,11 @@ class Autolink extends Regex
         $beginIndex = 0;
         $beginIndex = 0;
         foreach ($entities as $entity) {
         foreach ($entities as $entity) {
             if (isset($entity['screen_name'])) {
             if (isset($entity['screen_name'])) {
-                $text .= StringUtils::substr($tweet, $beginIndex, $entity['indices'][0] - $beginIndex + 1);
+                if(Str::startsWith($entity['screen_name'], '@')) {
+                    $text .= StringUtils::substr($tweet, $beginIndex, $entity['indices'][0] - $beginIndex);
+                } else {
+                    $text .= StringUtils::substr($tweet, $beginIndex, $entity['indices'][0] - $beginIndex + 1);
+                }
             } else {
             } else {
                 $text .= StringUtils::substr($tweet, $beginIndex, $entity['indices'][0] - $beginIndex);
                 $text .= StringUtils::substr($tweet, $beginIndex, $entity['indices'][0] - $beginIndex);
             }
             }
@@ -704,7 +710,7 @@ class Autolink extends Regex
 
 
         if (!empty($entity['list_slug'])) {
         if (!empty($entity['list_slug'])) {
             // Replace the list and username
             // Replace the list and username
-            $linkText = $entity['screen_name'].$entity['list_slug'];
+            $linkText = $entity['screen_name'];
             $class = $this->class_list;
             $class = $this->class_list;
             $url = $this->url_base_list.$linkText;
             $url = $this->url_base_list.$linkText;
         } else {
         } else {

+ 4 - 1
app/Util/Lexer/Extractor.php

@@ -9,6 +9,8 @@
 
 
 namespace App\Util\Lexer;
 namespace App\Util\Lexer;
 
 
+use Illuminate\Support\Str;
+
 /**
 /**
  * Twitter Extractor Class.
  * Twitter Extractor Class.
  *
  *
@@ -452,8 +454,9 @@ class Extractor extends Regex
             list($all, $before, $at, $username, $list_slug, $outer) = array_pad($match, 6, ['', 0]);
             list($all, $before, $at, $username, $list_slug, $outer) = array_pad($match, 6, ['', 0]);
             $start_position = $at[1] > 0 ? StringUtils::strlen(substr($tweet, 0, $at[1])) : $at[1];
             $start_position = $at[1] > 0 ? StringUtils::strlen(substr($tweet, 0, $at[1])) : $at[1];
             $end_position = $start_position + StringUtils::strlen($at[0]) + StringUtils::strlen($username[0]);
             $end_position = $start_position + StringUtils::strlen($at[0]) + StringUtils::strlen($username[0]);
+            $screenname = trim($all[0]) == '@'.$username[0] ? $username[0] : trim($all[0]);
             $entity = [
             $entity = [
-                'screen_name' => $username[0],
+                'screen_name' => $screenname,
                 'list_slug'   => $list_slug[0],
                 'list_slug'   => $list_slug[0],
                 'indices'     => [$start_position, $end_position],
                 'indices'     => [$start_position, $end_position],
             ];
             ];

+ 3 - 1
app/Util/Lexer/Regex.php

@@ -161,7 +161,9 @@ abstract class Regex
         //      $after in the following regular expression.  Note that we only use a
         //      $after in the following regular expression.  Note that we only use a
         //      look-ahead capture here and don't append $after when we return.
         //      look-ahead capture here and don't append $after when we return.
         $tmp['valid_mention_preceding_chars'] = '([^a-zA-Z0-9_!#\$%&*@@\/]|^|(?:^|[^a-z0-9_+~.-])RT:?)';
         $tmp['valid_mention_preceding_chars'] = '([^a-zA-Z0-9_!#\$%&*@@\/]|^|(?:^|[^a-z0-9_+~.-])RT:?)';
-        $re['valid_mentions_or_lists'] = '/'.$tmp['valid_mention_preceding_chars'].'(['.$tmp['at_signs'].'])([a-z0-9_]{1,20})(\/[a-z][a-z0-9_\-]{0,24})?(?=(.*|$))/iu';
+
+        $re['valid_mentions_or_lists'] = '/'.$tmp['valid_mention_preceding_chars'].'(['.$tmp['at_signs'].'])([a-z0-9_]{1,20})((\/[a-z][a-z0-9_\-]{0,24})?(?=(.*|$))(?:@[a-z0-9\.\-]+[a-z0-9]+)?)/i';
+
         $re['valid_reply'] = '/^(?:['.$tmp['spaces'].'])*['.$tmp['at_signs'].']([a-z0-9_]{1,20})(?=(.*|$))/iu';
         $re['valid_reply'] = '/^(?:['.$tmp['spaces'].'])*['.$tmp['at_signs'].']([a-z0-9_]{1,20})(?=(.*|$))/iu';
         $re['end_mention_match'] = '/\A(?:['.$tmp['at_signs'].']|['.$tmp['latin_accents'].']|:\/\/)/iu';
         $re['end_mention_match'] = '/\A(?:['.$tmp['at_signs'].']|['.$tmp['latin_accents'].']|:\/\/)/iu';