From 391d481fe1f78427121f71824123ed4fbe2e35b0 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Tue, 19 Mar 2019 03:22:51 +0000 Subject: [PATCH] REST API: Ensure "Allow" header is returned for OPTIONS requests. This changeset ensures `$request->set_url_params()` is called while fulfilling OPTIONS requests, where previously it was skipped because OPTIONS requests short-circuit the logic in `dispatch` which handles this setup for other request methods. Omitting the URL parameters prevented the Allow header from being set. Props killua99, noisysocks. Fixes #45753. Built from https://develop.svn.wordpress.org/trunk@44933 git-svn-id: http://core.svn.wordpress.org/trunk@44764 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/rest-api.php | 17 ++++++++++++++++- wp-includes/version.php | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/wp-includes/rest-api.php b/wp-includes/rest-api.php index a2e3363951..1c73b97824 100644 --- a/wp-includes/rest-api.php +++ b/wp-includes/rest-api.php @@ -615,12 +615,27 @@ function rest_handle_options_request( $response, $handler, $request ) { $data = array(); foreach ( $handler->get_routes() as $route => $endpoints ) { - $match = preg_match( '@^' . $route . '$@i', $request->get_route() ); + $match = preg_match( '@^' . $route . '$@i', $request->get_route(), $matches ); if ( ! $match ) { continue; } + $args = array(); + foreach ( $matches as $param => $value ) { + if ( ! is_int( $param ) ) { + $args[ $param ] = $value; + } + } + + foreach ( $endpoints as $endpoint ) { + // Remove the redundant preg_match argument. + unset( $args[0] ); + + $request->set_url_params( $args ); + $request->set_attributes( $endpoint ); + } + $data = $handler->get_data_for_route( $route, $endpoints, 'help' ); $response->set_matched_route( $route ); break; diff --git a/wp-includes/version.php b/wp-includes/version.php index e113c48c99..e65cae7136 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.2-alpha-44932'; +$wp_version = '5.2-alpha-44933'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.