mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-21 00:29:47 +00:00
Fix LinkCrawlWorker NoMethodError: undefined method `[]' for nil (#31144)
This commit is contained in:
parent
bfaa53343a
commit
fbf95216c5
|
@ -101,7 +101,7 @@ class LinkDetailsExtractor
|
||||||
end
|
end
|
||||||
|
|
||||||
def json
|
def json
|
||||||
@json ||= root_array(Oj.load(@data)).find { |obj| SUPPORTED_TYPES.include?(obj['@type']) } || {}
|
@json ||= root_array(Oj.load(@data)).compact.find { |obj| SUPPORTED_TYPES.include?(obj['@type']) } || {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -129,6 +129,24 @@ RSpec.describe LinkDetailsExtractor do
|
||||||
include_examples 'structured data'
|
include_examples 'structured data'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with the first tag is null' do
|
||||||
|
let(:html) { <<~HTML }
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<script type="application/ld+json">
|
||||||
|
null
|
||||||
|
</script>
|
||||||
|
<script type="application/ld+json">
|
||||||
|
#{ld_json}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
HTML
|
||||||
|
|
||||||
|
include_examples 'structured data'
|
||||||
|
end
|
||||||
|
|
||||||
context 'with preceding block of unsupported LD+JSON' do
|
context 'with preceding block of unsupported LD+JSON' do
|
||||||
let(:html) { <<~HTML }
|
let(:html) { <<~HTML }
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
|
|
Loading…
Reference in a new issue