Fix handling of `inLanguage` attribute in preview card processing (#27423)

local
Claire 7 months ago committed by GitHub
parent 23f8e93c64
commit 299aa71c8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/lib/link_details_extractor.rb
  2. 10
      spec/lib/link_details_extractor_spec.rb

@ -36,7 +36,8 @@ class LinkDetailsExtractor
end
def language
json['inLanguage']
lang = json['inLanguage']
lang.is_a?(Hash) ? (lang['alternateName'] || lang['name']) : lang
end
def type

@ -82,6 +82,10 @@ RSpec.describe LinkDetailsExtractor do
'name' => 'Pet News',
'url' => 'https://example.com',
},
'inLanguage' => {
name: 'English',
alternateName: 'en',
},
}.to_json
end
@ -115,6 +119,12 @@ RSpec.describe LinkDetailsExtractor do
expect(subject.provider_name).to eq 'Pet News'
end
end
describe '#language' do
it 'returns the language from structured data' do
expect(subject.language).to eq 'en'
end
end
end
context 'when is wrapped in CDATA tags' do

Loading…
Cancel
Save