File tree Expand file tree Collapse file tree
tests/phpunit/tests/rest-api Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3429,7 +3429,10 @@ function rest_convert_error_to_response( $error ) {
34293429 $ error ->get_all_error_data (),
34303430 static function ( $ status , $ error_data ) {
34313431 // Note: $error_data may not be an array (e.g. stdClass), so is_array() check is intentional.
3432- return is_array ( $ error_data ) && isset ( $ error_data ['status ' ] ) ? $ error_data ['status ' ] : $ status ;
3432+ if ( is_array ( $ error_data ) && isset ( $ error_data ['status ' ] ) && is_numeric ( $ error_data ['status ' ] ) ) {
3433+ $ status = (int ) $ error_data ['status ' ];
3434+ }
3435+ return $ status ;
34333436 },
34343437 500
34353438 );
Original file line number Diff line number Diff line change @@ -605,6 +605,19 @@ public function test_error_to_response_with_stdclass_data() {
605605 $ this ->assertSame ( 500 , $ response ->get_status () );
606606 }
607607
608+ /**
609+ * @ticket 64901
610+ */
611+ public function test_error_to_response_with_non_numeric_status () {
612+ $ error = new WP_Error ( 'test ' , 'test ' , array ( 'status ' => 'forbidden ' ) );
613+
614+ $ response = rest_convert_error_to_response ( $ error );
615+ $ this ->assertInstanceOf ( 'WP_REST_Response ' , $ response );
616+
617+ // Non-numeric status should be ignored, status should default to 500.
618+ $ this ->assertSame ( 500 , $ response ->get_status () );
619+ }
620+
608621 public function test_rest_error () {
609622 $ data = array (
610623 'code ' => 'wp-api-test-error ' ,
You can’t perform that action at this time.
0 commit comments