Changeset 62107
- Timestamp:
- 03/24/2026 05:38:12 PM (4 days ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
src/wp-includes/rest-api.php (modified) (1 diff)
-
tests/phpunit/tests/rest-api/rest-server.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r62075 r62107 3428 3428 $status = array_reduce( 3429 3429 $error->get_all_error_data(), 3430 static function ( $status, $error_data ) { 3431 return $error_data['status'] ?? $status; 3430 /** 3431 * @param int $status Status. 3432 * @param mixed $error_data Error data. 3433 */ 3434 static function ( int $status, $error_data ): int { 3435 if ( is_array( $error_data ) && isset( $error_data['status'] ) && is_numeric( $error_data['status'] ) ) { 3436 $status = (int) $error_data['status']; 3437 } 3438 return $status; 3432 3439 }, 3433 3440 500 -
trunk/tests/phpunit/tests/rest-api/rest-server.php
r60635 r62107 591 591 $this->assertSame( 'more_data', $response->get_data()['data'] ); 592 592 $this->assertSame( array( array( 'status' => 400 ) ), $response->get_data()['additional_data'] ); 593 } 594 595 /** 596 * @ticket 64901 597 */ 598 public function test_error_to_response_with_stdclass_data() { 599 $error = new WP_Error( 'test', 'test', (object) array( 'status' => 400 ) ); 600 601 $response = rest_convert_error_to_response( $error ); 602 $this->assertInstanceOf( WP_REST_Response::class, $response ); 603 604 // stdClass data should not cause a fatal, status should default to 500. 605 $this->assertSame( 500, $response->get_status() ); 606 } 607 608 /** 609 * @ticket 64901 610 */ 611 public function test_error_to_response_with_multi_status_non_numeric_status() { 612 $error = new WP_Error( 'test', 'test', array( 'status' => array( 'feeling' => 'happy' ) ) ); 613 $error->add_data( array( 'status' => 400 ), 'test' ); 614 $error->add_data( array( 'status' => array( 'feeling' => 'bleh' ) ), 'test' ); 615 616 $response = rest_convert_error_to_response( $error ); 617 $this->assertInstanceOf( WP_REST_Response::class, $response ); 618 619 $this->assertSame( 400, $response->get_status() ); 593 620 } 594 621
Note: See TracChangeset
for help on using the changeset viewer.