Skip to content

Commit

Permalink
Fix crash when processing Flag activity with no status (#26189)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire committed Jul 27, 2023
1 parent b4e739f commit 6c3c5bb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/lib/activitypub/activity/flag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def perform

target_accounts.each do |target_account|
target_statuses = target_statuses_by_account[target_account.id]
replied_to_accounts = Account.local.where(id: target_statuses.filter_map(&:in_reply_to_account_id))
replied_to_accounts = target_statuses.nil? ? [] : Account.local.where(id: target_statuses.filter_map(&:in_reply_to_account_id))

next if target_account.suspended? || (!target_account.local? && replied_to_accounts.none?)

Expand Down
29 changes: 29 additions & 0 deletions spec/lib/activitypub/activity/flag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,35 @@
expect(report.status_ids).to eq []
end
end

context 'when an account is passed but no status' do
let(:mentioned) { Fabricate(:account) }

let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
id: flag_id,
type: 'Flag',
content: 'Boo!!',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: [
ActivityPub::TagManager.instance.uri_for(flagged),
],
}.with_indifferent_access
end

before do
subject.perform
end

it 'creates a report with no attached status' do
report = Report.find_by(account: sender, target_account: flagged)

expect(report).to_not be_nil
expect(report.comment).to eq 'Boo!!'
expect(report.status_ids).to eq []
end
end
end

describe '#perform with a defined uri' do
Expand Down

0 comments on commit 6c3c5bb

Please sign in to comment.