Skip to content

Commit 63fb115

Browse files
authored
Fix: set_object falsely overwrites the Activity-ID with a default (#1318)
1 parent 114f27a commit 63fb115

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
* Enforce 200 status header for valid ActivityPub requests.
2626
* Integration of content-visibility setup in the block editor.
2727
* Update CLI commands to the new scheduler refactorings.
28+
* `Activity::set_object` falsely overwrites the Activity-ID with a default.
2829

2930
## [5.1.0] - 2025-02-06
3031

includes/activity/class-activity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public function set_object( $data ) {
178178
$this->set( 'object', $data );
179179

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

184184
return;

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ For reasons of data protection, it is not possible to see the followers of other
141141
* Fixed: Enforce 200 status header for valid ActivityPub requests.
142142
* Fixed: Integration of content-visibility setup in the block editor.
143143
* Fixed: Update CLI commands to the new scheduler refactorings.
144+
* Fixed: `Activity::set_object` falsely overwrites the Activity-ID with a default.
144145

145146
= 5.1.0 =
146147

tests/includes/activity/class-test-activity.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public function test_object_transformation() {
7272

7373
/**
7474
* Test activity object.
75+
*
76+
* @covers ::init_from_array
7577
*/
7678
public function test_activity_object() {
7779
$test_array = array(
@@ -92,8 +94,34 @@ public function test_activity_object() {
9294

9395
/**
9496
* Test activity object.
97+
*
98+
* @covers ::init_from_array
9599
*/
96100
public function test_activity_object_url() {
101+
$test_array = array(
102+
'id' => 'https://example.com/id/123',
103+
'type' => 'Follow',
104+
'object' => 'https://example.com/post/123',
105+
);
106+
107+
$activity = Activity::init_from_array( $test_array );
108+
109+
$this->assertEquals( 'https://example.com/id/123', $activity->get_id() );
110+
111+
$test_array2 = array(
112+
'type' => 'Follow',
113+
'object' => 'https://example.com/post/123',
114+
);
115+
116+
$activity2 = Activity::init_from_array( $test_array2 );
117+
118+
$this->assertTrue( str_starts_with( $activity2->get_id(), 'https://example.com/post/123#activity-follow-' ) );
119+
}
120+
121+
/**
122+
* Test activity object.
123+
*/
124+
public function test_activity_object_id() {
97125
$id = 'https://example.com/author/123';
98126

99127
// Build the update.

0 commit comments

Comments
 (0)