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

This commit is contained in:
Claire authored and GitHub committed 2025-05-06 09:51:42 +00:00
1 parent 41d00bc28b
commit 22e2e7f02b
2 files changed
+20 -2

No files matched your search

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