Make WordPress Core


Ignore:
Timestamp:
08/14/2025 09:14:18 PM (8 months ago)
Author:
SergeyBiryukov
Message:

REST API: Correct error handling in WP_REST_Server::serve_batch_request_v1().

This aims to avoid a fatal error when hitting the batch request endpoint with a malformed URL.

Follow-up to [49252].

Props bor0, SirLouen, SergeyBiryukov.
Fixes #63502.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-server.php

    r60251 r60635  
    23312331
    23322332    /**
     2333     * @ticket 63502
     2334     */
     2335    public function test_batch_request_with_malformed_url() {
     2336        $request = new WP_REST_Request( 'POST', '/batch/v1' );
     2337        $request->set_header( 'Content-Type', 'application/json' );
     2338        $request->set_body_params(
     2339            array(
     2340                'requests' => array(
     2341                    array(
     2342                        'method' => 'POST',
     2343                        'path'   => 'http://user@:80',
     2344                    ),
     2345                ),
     2346            )
     2347        );
     2348
     2349        $response = rest_get_server()->dispatch( $request );
     2350        $data     = $response->get_data()['responses'][0]['body'] ?? null;
     2351
     2352        $this->assertIsArray( $data );
     2353        $this->assertSame( 'parse_path_failed', $data['code'] );
     2354    }
     2355
     2356    /**
    23332357     * @ticket 51020
    23342358     */
Note: See TracChangeset for help on using the changeset viewer.