about summary refs log tree commit diff
path: root/app/services/fetch_link_card_service.rb
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2018-12-17 19:19:45 +0100
committerEugen Rochko <eugen@zeonfederated.com>2018-12-17 19:19:45 +0100
commite709b8da0d685d3cc48d430a9761896094f67d72 (patch)
tree8d60d548237c7478bb974e2813288fdda11a8862 /app/services/fetch_link_card_service.rb
parent4ede51743e5b9121a49e9131f91cf012fab410f8 (diff)
Ignore low-confidence CharlockHolmes guesses when parsing link cards (#9510)
* Add failing test for windows-1251 link cards

* Ignore low-confidence CharlockHolmes guesses

Fixes #9466

* Fix no method error when charlock holmes cannot detect charset
Diffstat (limited to 'app/services/fetch_link_card_service.rb')
-rw-r--r--app/services/fetch_link_card_service.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/app/services/fetch_link_card_service.rb b/app/services/fetch_link_card_service.rb
index 38c578de2..7979c312e 100644
--- a/app/services/fetch_link_card_service.rb
+++ b/app/services/fetch_link_card_service.rb
@@ -137,7 +137,8 @@ class FetchLinkCardService < BaseService
     detector.strip_tags = true
 
     guess      = detector.detect(@html, @html_charset)
-    page       = Nokogiri::HTML(@html, nil, guess&.fetch(:encoding, nil))
+    encoding   = guess&.fetch(:confidence, 0).to_i > 60 ? guess&.fetch(:encoding, nil) : nil
+    page       = Nokogiri::HTML(@html, nil, encoding)
     player_url = meta_property(page, 'twitter:player')
 
     if player_url && !bad_url?(Addressable::URI.parse(player_url))