Make WordPress Core


Ignore:
Timestamp:
03/15/2024 11:23:18 AM (15 months ago)
Author:
swissspidy
Message:

REST API: Prevent error when passing invalid type parameter to search endpoint.

In WP_REST_Search_Controller, the type parameter is accessed via the sanitization callback for the subtype parameter, which is too early for type itself to be already sanitized. This change adds a type check in the get_search_handler() method to prevent errors when the type doesn’t match.

Props swissspidy, timothyblynjacobs, dd32.
Fixes #60771.

File:
1 edited

Legend:

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

    r56547 r57839  
    889889        );
    890890    }
     891
     892    /**
     893     * @ticket 60771
     894     */
     895    public function test_sanitize_subtypes_validates_type() {
     896        $response = $this->do_request_with_params(
     897            array(
     898                'subtype' => 'page',
     899                'type'    => array( 'invalid' ),
     900            )
     901        );
     902
     903        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     904    }
    891905}
Note: See TracChangeset for help on using the changeset viewer.