about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/formatter.rb10
1 files changed, 3 insertions, 7 deletions
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb
index 12e79c9b1..1d8e90d1f 100644
--- a/app/lib/formatter.rb
+++ b/app/lib/formatter.rb
@@ -61,20 +61,15 @@ class Formatter
     result = ''
 
     last_index = entities.reduce(0) do |index, entity|
+      normalized_url = Addressable::URI.parse(entity[:url]).normalize
       indices = entity[:indices]
       result += encode(chars[index...indices.first].join)
-      result += Twitter::Autolink.send(:link_to_text, entity, link_html(entity[:url]), entity[:url], html_attrs)
+      result += Twitter::Autolink.send(:link_to_text, entity, link_html(entity[:url]), normalized_url, html_attrs)
       indices.last
     end
     result += encode(chars[last_index..-1].join)
   end
 
-  def link_urls(html)
-    Twitter::Autolink.auto_link_urls(html, url_target: '_blank',
-                                           link_attribute_block: lambda { |_, a| a[:rel] << ' noopener' },
-                                           link_text_block: lambda { |_, text| link_html(text) })
-  end
-
   def link_mentions(html, mentions)
     html.gsub(Account::MENTION_RE) do |match|
       acct    = Account::MENTION_RE.match(match)[1]
@@ -102,6 +97,7 @@ class Formatter
   end
 
   def link_html(url)
+    url = Addressable::URI.parse(url).display_uri.to_s
     prefix = url.match(/\Ahttps?:\/\/(www\.)?/).to_s
     text   = url[prefix.length, 30]
     suffix = url[prefix.length + 30..-1]