-
Notifications
You must be signed in to change notification settings - Fork 83
Fix get_object_title()
#2502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix get_object_title()
#2502
Conversation
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.
There was a problem hiding this 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.
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.
There is an option that
Activity::get_object()orBase_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:
get_object_title()to return empty string when object is an arrayOther information:
Testing instructions:
Changelog entry
Changelog Entry Details
Significance
Type
Message
Improved handling of unusual activity data to avoid errors when activities contain unexpected formats.