]> cat aescling's git repositories - mastodon.git/commitdiff
Show multibyte URI preview card (#2363)
authorYamagishi Kazutoshi <ykzts@desire.sh>
Sun, 23 Apr 2017 17:08:59 +0000 (02:08 +0900)
committerEugen <eugen@zeonfederated.com>
Sun, 23 Apr 2017 17:08:59 +0000 (19:08 +0200)
app/services/fetch_link_card_service.rb

index f24ebb82b812cb8323c6c14399e9e052ad70c0f7..31f9be194eb699b2e359da1ef2975ab876bee8ff 100644 (file)
@@ -1,11 +1,12 @@
 # frozen_string_literal: true
 
 class FetchLinkCardService < BaseService
+  URL_PATTERN = %r{https?://\S+}
   USER_AGENT = "#{HTTP::Request::USER_AGENT} (Mastodon/#{Mastodon::VERSION}; +http://#{Rails.configuration.x.local_domain}/)"
 
   def call(status)
     # Get first http/https URL that isn't local
-    url = URI.extract(status.text).reject { |uri| (uri =~ /\Ahttps?:\/\//).nil? || TagManager.instance.local_url?(uri) }.first
+    url = status.text.match(URL_PATTERN).to_a.reject { |uri| TagManager.instance.local_url?(uri) }.first
 
     return if url.nil?