Changeset 7511
- Timestamp:
- 09/14/2026 07:40:20 PM (2 months ago)
- Location:
- trunk
- Files:
-
- 5 edited
-
CHANGELOG.md (modified) (1 diff)
-
src/includes/replies/functions.php (modified) (1 diff)
-
src/includes/topics/functions.php (modified) (1 diff)
-
tests/phpunit/testcases/replies/functions/permissions.php (modified) (3 diffs)
-
tests/phpunit/testcases/topics/functions/permissions.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/CHANGELOG.md
r7509 r7511 51 51 ### Security 52 52 53 - Validated and filtered topic titles when converting replies or splitting 54 topics. 53 55 - Prevented subscription emails from disclosing content to users who can no 54 56 longer access a restricted forum. -
trunk/src/includes/replies/functions.php
r7509 r7511 1406 1406 } 1407 1407 1408 // Filter the new topic title 1409 $destination_topic_title = apply_filters( 'bbp_new_topic_pre_title', $destination_topic_title ); 1410 1411 // Title cannot be empty 1412 if ( empty( $destination_topic_title ) ) { 1413 bbp_add_error( 'bbp_topic_title', __( '<strong>Error</strong>: Your topic needs a title.', 'bbpress' ) ); 1414 } 1415 1416 // Title too long 1417 if ( bbp_is_title_too_long( $destination_topic_title ) ) { 1418 bbp_add_error( 'bbp_topic_title', __( '<strong>Error</strong>: Your title is too long.', 'bbpress' ) ); 1419 } 1420 1421 // Bail before converting the reply if there are errors 1422 if ( bbp_has_errors() ) { 1423 break; 1424 } 1425 1408 1426 // Update the topic 1409 1427 $destination_topic_id = wp_update_post( -
trunk/src/includes/topics/functions.php
r7509 r7511 1515 1515 } 1516 1516 1517 // Filter the new topic title 1518 $destination_topic_title = apply_filters( 'bbp_new_topic_pre_title', $destination_topic_title ); 1519 1520 // Title cannot be empty 1521 if ( empty( $destination_topic_title ) ) { 1522 bbp_add_error( 'bbp_topic_title', __( '<strong>Error</strong>: Your topic needs a title.', 'bbpress' ) ); 1523 } 1524 1525 // Title too long 1526 if ( bbp_is_title_too_long( $destination_topic_title ) ) { 1527 bbp_add_error( 'bbp_topic_title', __( '<strong>Error</strong>: Your title is too long.', 'bbpress' ) ); 1528 } 1529 1530 // Bail before converting the reply if there are errors 1531 if ( bbp_has_errors() ) { 1532 break; 1533 } 1534 1517 1535 // Update the topic 1518 1536 $destination_topic_id = wp_update_post( -
trunk/tests/phpunit/testcases/replies/functions/permissions.php
r7509 r7511 145 145 } 146 146 147 protected function submit_reply_move( $reply_id, $move_option, $destination_topic_id = 0 ) {147 protected function submit_reply_move( $reply_id, $move_option, $destination_topic_id = 0, $destination_title = null ) { 148 148 $home_url = wp_parse_url( home_url( '/' ) ); 149 149 $_SERVER['HTTP_HOST'] = $home_url['host']; … … 158 158 $_POST['bbp_destination_topic'] = $destination_topic_id; 159 159 $_REQUEST['_wpnonce'] = wp_create_nonce( 'bbp-move-reply_' . $reply_id ); 160 161 if ( null !== $destination_title ) { 162 $_POST['bbp_reply_move_destination_title'] = $destination_title; 163 } 160 164 161 165 $did_redirect = false; … … 346 350 bbpress()->errors = new WP_Error(); 347 351 348 $did_redirect = $this->submit_reply_move( $reply_id, 'topic' ); 352 $filter_title = function( $title ) { 353 return $title . ' filtered'; 354 }; 355 356 add_filter( 'bbp_new_topic_pre_title', $filter_title ); 357 $did_redirect = $this->submit_reply_move( $reply_id, 'topic', 0, 'Converted reply' ); 358 remove_filter( 'bbp_new_topic_pre_title', $filter_title ); 349 359 350 360 $this->assertSame( array(), bbpress()->errors->get_error_codes() ); 351 361 $this->assertSame( bbp_get_topic_post_type(), get_post_type( $reply_id ) ); 362 $this->assertSame( 'Converted reply filtered', get_post_field( 'post_title', $reply_id ) ); 352 363 $this->assertSame( $forum_id, wp_get_post_parent_id( $reply_id ) ); 353 364 $this->assertSame( $reply_id, (int) get_post_meta( $reply_id, '_bbp_topic_id', true ) ); 354 365 $this->assertTrue( $did_redirect ); 366 } 367 368 /** 369 * @covers ::bbp_move_reply_handler 370 */ 371 public function test_participant_cannot_convert_reply_to_topic_with_long_title() { 372 $user_id = $this->factory->user->create( array( 'role' => bbp_get_participant_role() ) ); 373 $forum_id = $this->factory->forum->create(); 374 $source_topic_id = $this->factory->topic->create( 375 array( 376 'post_author' => $user_id, 377 'post_parent' => $forum_id, 378 'topic_meta' => array( 'forum_id' => $forum_id ), 379 ) 380 ); 381 $reply_id = $this->factory->reply->create( 382 array( 383 'post_author' => $user_id, 384 'post_parent' => $source_topic_id, 385 'reply_meta' => array( 386 'forum_id' => $forum_id, 387 'topic_id' => $source_topic_id, 388 ), 389 ) 390 ); 391 392 $this->set_current_user( $user_id ); 393 bbpress()->errors = new WP_Error(); 394 395 $did_redirect = $this->submit_reply_move( $reply_id, 'topic', 0, str_repeat( 'a', bbp_get_title_max_length() + 1 ) ); 396 397 $this->assertContains( 'bbp_topic_title', bbpress()->errors->get_error_codes() ); 398 $this->assertSame( bbp_get_reply_post_type(), get_post_type( $reply_id ) ); 399 $this->assertSame( $source_topic_id, wp_get_post_parent_id( $reply_id ) ); 400 $this->assertSame( $source_topic_id, bbp_get_reply_topic_id( $reply_id ) ); 401 $this->assertFalse( $did_redirect ); 355 402 } 356 403 -
trunk/tests/phpunit/testcases/topics/functions/permissions.php
r7487 r7511 33 33 } 34 34 35 protected function submit_topic_split( $reply_id, $source_topic_id, $split_option ) {35 protected function submit_topic_split( $reply_id, $source_topic_id, $split_option, $destination_title = null ) { 36 36 $home_url = wp_parse_url( home_url( '/' ) ); 37 37 $_SERVER['HTTP_HOST'] = $home_url['host']; … … 45 45 $_POST['bbp_topic_split_option'] = $split_option; 46 46 $_REQUEST['_wpnonce'] = wp_create_nonce( 'bbp-split-topic_' . $source_topic_id ); 47 48 if ( null !== $destination_title ) { 49 $_POST['bbp_topic_split_destination_title'] = $destination_title; 50 } 47 51 48 52 $did_redirect = false; … … 135 139 bbpress()->errors = new WP_Error(); 136 140 137 $did_redirect = $this->submit_topic_split( $reply_id, $source_topic_id, 'reply' ); 141 $filter_title = function( $title ) { 142 return $title . ' filtered'; 143 }; 144 145 add_filter( 'bbp_new_topic_pre_title', $filter_title ); 146 $did_redirect = $this->submit_topic_split( $reply_id, $source_topic_id, 'reply', 'Split topic' ); 147 remove_filter( 'bbp_new_topic_pre_title', $filter_title ); 138 148 139 149 $this->assertSame( array(), bbpress()->errors->get_error_codes() ); 140 150 $this->assertSame( bbp_get_topic_post_type(), get_post_type( $reply_id ) ); 151 $this->assertSame( 'Split topic filtered', get_post_field( 'post_title', $reply_id ) ); 141 152 $this->assertSame( $forum_id, wp_get_post_parent_id( $reply_id ) ); 142 153 $this->assertSame( $reply_id, (int) get_post_meta( $reply_id, '_bbp_topic_id', true ) ); 143 154 $this->assertTrue( $did_redirect ); 144 155 } 156 157 /** 158 * @covers ::bbp_split_topic_handler 159 */ 160 public function test_moderator_cannot_convert_split_reply_to_topic_with_long_title() { 161 $user_id = $this->factory->user->create(); 162 $other_user_id = $this->factory->user->create( array( 'role' => bbp_get_participant_role() ) ); 163 $forum_id = $this->factory->forum->create(); 164 $source_topic_id = $this->factory->topic->create( 165 array( 166 'post_author' => $other_user_id, 167 'post_parent' => $forum_id, 168 'topic_meta' => array( 'forum_id' => $forum_id ), 169 ) 170 ); 171 $reply_id = $this->factory->reply->create( 172 array( 173 'post_author' => $other_user_id, 174 'post_parent' => $source_topic_id, 175 'reply_meta' => array( 176 'forum_id' => $forum_id, 177 'topic_id' => $source_topic_id, 178 ), 179 ) 180 ); 181 182 bbp_set_user_role( $user_id, bbp_get_moderator_role() ); 183 $this->set_current_user( $user_id ); 184 bbpress()->errors = new WP_Error(); 185 186 $did_redirect = $this->submit_topic_split( $reply_id, $source_topic_id, 'reply', str_repeat( 'a', bbp_get_title_max_length() + 1 ) ); 187 188 $this->assertContains( 'bbp_topic_title', bbpress()->errors->get_error_codes() ); 189 $this->assertSame( bbp_get_reply_post_type(), get_post_type( $reply_id ) ); 190 $this->assertSame( $source_topic_id, wp_get_post_parent_id( $reply_id ) ); 191 $this->assertSame( $source_topic_id, bbp_get_reply_topic_id( $reply_id ) ); 192 $this->assertFalse( $did_redirect ); 193 } 145 194 }
Note:
See TracChangeset
for help on using the changeset viewer.