Rewrite Rules: Add self-describing variables to rewrite matcher.

The rewrite rule matching code in WP::parse_request() used an unclear variable `$request` to represent the requested path (e.g. "2016/05/03") as well as a deceptively named variable `$request_uri`, which actually represents the requested file when an install used PATHINFO links. 

Those variables are replaced with `$requested_path` and `$requested_file` respectively for clarity.

Fixes #36674.

Built from https://develop.svn.wordpress.org/trunk@37356


git-svn-id: http://core.svn.wordpress.org/trunk@37322 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Eric Lewis 2016-05-03 19:36:28 +00:00
parent c7a2b7683b
commit 98d5d4919c
2 changed files with 11 additions and 10 deletions

View File

@ -56,7 +56,7 @@ class WP {
public $query_string; public $query_string;
/** /**
* Permalink or requested URI. * The request path, e.g. `2015/05/06`.
* *
* @since 2.0.0 * @since 2.0.0
* @access public * @access public
@ -202,18 +202,19 @@ class WP {
// The requested permalink is in $pathinfo for path info requests and // The requested permalink is in $pathinfo for path info requests and
// $req_uri for other requests. // $req_uri for other requests.
if ( ! empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) { if ( ! empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) {
$request = $pathinfo; $requested_path = $pathinfo;
} else { } else {
// If the request uri is the index, blank it out so that we don't try to match it against a rule. // If the request uri is the index, blank it out so that we don't try to match it against a rule.
if ( $req_uri == $wp_rewrite->index ) if ( $req_uri == $wp_rewrite->index )
$req_uri = ''; $req_uri = '';
$request = $req_uri; $requested_path = $req_uri;
} }
$requested_file = $req_uri;
$this->request = $request; $this->request = $requested_path;
// Look for matches. // Look for matches.
$request_match = $request; $request_match = $requested_path;
if ( empty( $request_match ) ) { if ( empty( $request_match ) ) {
// An empty request could only match against ^$ regex // An empty request could only match against ^$ regex
if ( isset( $rewrite['$'] ) ) { if ( isset( $rewrite['$'] ) ) {
@ -223,9 +224,9 @@ class WP {
} }
} else { } else {
foreach ( (array) $rewrite as $match => $query ) { foreach ( (array) $rewrite as $match => $query ) {
// If the requesting file is the anchor of the match, prepend it to the path info. // If the requested file is the anchor of the match, prepend it to the path info.
if ( ! empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request ) if ( ! empty($requested_file) && strpos($match, $requested_file) === 0 && $requested_file != $requested_path )
$request_match = $req_uri . '/' . $request; $request_match = $requested_file . '/' . $requested_path;
if ( preg_match("#^$match#", $request_match, $matches) || if ( preg_match("#^$match#", $request_match, $matches) ||
preg_match("#^$match#", urldecode($request_match), $matches) ) { preg_match("#^$match#", urldecode($request_match), $matches) ) {
@ -269,7 +270,7 @@ class WP {
} }
// If req_uri is empty or if it is a request for ourself, unset error. // If req_uri is empty or if it is a request for ourself, unset error.
if ( empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) { if ( empty($requested_path) || $requested_file == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
unset( $error, $_GET['error'] ); unset( $error, $_GET['error'] );
if ( isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) if ( isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false )

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.6-alpha-37355'; $wp_version = '4.6-alpha-37356';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.