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

This commit is contained in:
Claire 2025-05-06 11:51:42 +02:00 committed by GitHub
parent 41d00bc28b
commit 22e2e7f02b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View file

@ -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

View file

@ -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