From 5d7c852283b1afd603f169e9ace80bf1714795d0 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 13 Nov 2021 23:07:13 +0100 Subject: [PATCH] Fix no link previews being generated for pages with invalid structured data (#16979) Fix #16955 --- app/lib/link_details_extractor.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/lib/link_details_extractor.rb b/app/lib/link_details_extractor.rb index 3876173e0..8b38e8d0c 100644 --- a/app/lib/link_details_extractor.rb +++ b/app/lib/link_details_extractor.rb @@ -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