Skip to content

Commit

Permalink
Fix: set_object falsely overwrites the Activity-ID with a default (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pfefferle authored Feb 13, 2025
1 parent 114f27a commit 63fb115
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Enforce 200 status header for valid ActivityPub requests.
* Integration of content-visibility setup in the block editor.
* Update CLI commands to the new scheduler refactorings.
* `Activity::set_object` falsely overwrites the Activity-ID with a default.

## [5.1.0] - 2025-02-06

Expand Down
2 changes: 1 addition & 1 deletion includes/activity/class-activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function set_object( $data ) {
$this->set( 'object', $data );

// Check if `$data` is a URL and use it to generate an ID then.
if ( is_string( $data ) && filter_var( $data, FILTER_VALIDATE_URL ) ) {
if ( is_string( $data ) && filter_var( $data, FILTER_VALIDATE_URL ) && ! $this->get_id() ) {
$this->set( 'id', $data . '#activity-' . strtolower( $this->get_type() ) . '-' . time() );

return;
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ For reasons of data protection, it is not possible to see the followers of other
* Fixed: Enforce 200 status header for valid ActivityPub requests.
* Fixed: Integration of content-visibility setup in the block editor.
* Fixed: Update CLI commands to the new scheduler refactorings.
* Fixed: `Activity::set_object` falsely overwrites the Activity-ID with a default.

= 5.1.0 =

Expand Down
28 changes: 28 additions & 0 deletions tests/includes/activity/class-test-activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public function test_object_transformation() {

/**
* Test activity object.
*
* @covers ::init_from_array
*/
public function test_activity_object() {
$test_array = array(
Expand All @@ -92,8 +94,34 @@ public function test_activity_object() {

/**
* Test activity object.
*
* @covers ::init_from_array
*/
public function test_activity_object_url() {
$test_array = array(
'id' => 'https://example.com/id/123',
'type' => 'Follow',
'object' => 'https://example.com/post/123',
);

$activity = Activity::init_from_array( $test_array );

$this->assertEquals( 'https://example.com/id/123', $activity->get_id() );

$test_array2 = array(
'type' => 'Follow',
'object' => 'https://example.com/post/123',
);

$activity2 = Activity::init_from_array( $test_array2 );

$this->assertTrue( str_starts_with( $activity2->get_id(), 'https://example.com/post/123#activity-follow-' ) );
}

/**
* Test activity object.
*/
public function test_activity_object_id() {
$id = 'https://example.com/author/123';

// Build the update.
Expand Down

0 comments on commit 63fb115

Please sign in to comment.