Skip to content

Conversation

@pfefferle
Copy link
Member

@pfefferle pfefferle commented Nov 19, 2025

There is an option that Activity::get_object() or Base_Object::get_object() returns an array. This PR checks for that special case.

Updated get_object_title to return an empty string if the input is an array, improving robustness when handling different types of activity objects.

Proposed changes:

  • Added array type check to get_object_title() to return empty string when object is an array
  • Updated PHPDoc to reflect that the method can accept arrays
  • Added comprehensive test coverage for array, null, string, and object inputs

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • Go to '..'

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

Improved handling of unusual activity data to avoid errors when activities contain unexpected formats.

Updated get_object_title to return an empty string if the input is an array, improving robustness when handling different types of activity objects.
Add comprehensive test coverage for the get_object_title method's handling of different object types:
- Array objects (the bug fix case)
- Null objects
- String URL objects
- Objects with name property
- Objects with content but no name

All tests verify that inbox posts are created correctly without errors regardless of the object type.
Copilot AI review requested due to automatic review settings November 19, 2025 09:41
@pfefferle pfefferle self-assigned this Nov 19, 2025
@pfefferle pfefferle requested a review from obenland November 19, 2025 09:42
Copilot finished reviewing on behalf of pfefferle November 19, 2025 09:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a potential fatal error in the Inbox::get_object_title() method by adding a check to handle cases where Activity::get_object() or Base_Object::get_object() returns an array instead of an object. This can occur with certain ActivityPub implementations.

Key changes:

  • Added array type check to get_object_title() to return empty string when object is an array
  • Updated PHPDoc to reflect that the method can accept arrays
  • Added comprehensive test coverage for array, null, string, and object inputs

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
includes/collection/class-inbox.php Added is_array() check in get_object_title() to prevent calling object methods on arrays, and updated PHPDoc to include array type
tests/phpunit/tests/includes/collection/class-test-inbox.php Added 5 comprehensive tests covering array objects, null objects, string objects, objects with names, and objects with content but no names

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

matticbot and others added 4 commits November 19, 2025 11:47
Introduces a unit test to verify that the inbox can handle Flag activities where the object is an array of URLs, reflecting real-world Mastodon moderation report scenarios. Ensures that such activities are processed without errors and the corresponding post is created correctly.
Replaces Mastodon-specific URLs with generic example URLs in the test_add_flag_activity_with_url_array test to improve clarity and generalize the test case.
@pfefferle pfefferle merged commit b2495e1 into trunk Nov 19, 2025
15 checks passed
@pfefferle pfefferle deleted the fix/get_object_title branch November 19, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants