Fix crash when `likes` or `shares` collections are not inlined, for real (#34619)

pull/34623/head
Claire 6 months ago committed by GitHub
parent 41d00bc28b
commit 22e2e7f02b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -95,11 +95,11 @@ class ActivityPub::Parser::StatusParser
end
def favourites_count
@object.dig('likes', 'totalItems') if @object.is_a?(Hash)
@object['likes']['totalItems'] if @object.is_a?(Hash) && @object['likes'].is_a?(Hash)
end
def reblogs_count
@object.dig('shares', 'totalItems') if @object.is_a?(Hash)
@object['shares']['totalItems'] if @object.is_a?(Hash) && @object['shares'].is_a?(Hash)
end
def quote_policy

@ -49,6 +49,24 @@ RSpec.describe ActivityPub::Parser::StatusParser do
)
end
context 'when the likes collection is not inlined' do
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), 'post1'].join('/'),
type: 'Note',
to: 'https://www.w3.org/ns/activitystreams#Public',
content: 'bleh',
published: 1.hour.ago.utc.iso8601,
updated: 1.hour.ago.utc.iso8601,
likes: 'https://example.com/collections/likes',
}
end
it 'does not raise an error' do
expect { subject.favourites_count }.to_not raise_error
end
end
describe '#quote_policy' do
subject do
described_class

Loading…
Cancel
Save