From c47658c7c5326512f91dd8415acce5d071aee0fc Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Fri, 7 Jul 2017 21:47:44 +0530 Subject: [PATCH] FIX: first @mention/#hashtag is not a hyperlink in Twitter onebox https://meta.discourse.org/t/first-mention-is-not-a-hyperlink-in-twitter-onebox/65665 --- lib/twitter_api.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/twitter_api.rb b/lib/twitter_api.rb index 373c6838f1f..2c9ce48a601 100644 --- a/lib/twitter_api.rb +++ b/lib/twitter_api.rb @@ -56,7 +56,7 @@ class TwitterApi protected def link_handles_in(text) - text.scan(/\s@(\w+)/).flatten.uniq.each do |handle| + text.scan(/(?:^|\s)@(\w+)/).flatten.uniq.each do |handle| text.gsub!("@#{handle}", [ "", "@#{handle}", @@ -68,7 +68,7 @@ class TwitterApi end def link_hashtags_in(text) - text.scan(/\s#(\w+)/).flatten.uniq.each do |hashtag| + text.scan(/(?:^|\s)#(\w+)/).flatten.uniq.each do |hashtag| text.gsub!("##{hashtag}", [ "",