]> cat aescling's git repositories - mastodon.git/commitdiff
Fix no link previews being generated for pages with invalid structured data (#16979)
authorEugen Rochko <eugen@zeonfederated.com>
Sat, 13 Nov 2021 22:07:13 +0000 (23:07 +0100)
committerGitHub <noreply@github.com>
Sat, 13 Nov 2021 22:07:13 +0000 (23:07 +0100)
Fix #16955

app/lib/link_details_extractor.rb

index 3876173e0d25716334a51e14ffaa3b6f9a8fddc1..8b38e8d0c6e7e4524284f2eba82c93c5a2673727 100644 (file)
@@ -59,7 +59,7 @@ class LinkDetailsExtractor
     end
 
     def json
-      @json ||= Oj.load(@data)
+      @json ||= first_of_value(Oj.load(@data))
     end
   end
 
@@ -178,6 +178,8 @@ class LinkDetailsExtractor
     @structured_data ||= begin
       json_ld = document.xpath('//script[@type="application/ld+json"]').map(&:content).first
       json_ld.present? ? StructuredData.new(json_ld) : nil
+    rescue Oj::ParseError
+      nil
     end
   end