Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function parse_request( $extra_query_vars = '' ) {
$home_path_regex = '';
if ( is_string( $home_path ) && '' !== $home_path ) {
$home_path = trim( $home_path, '/' );
$home_path_regex = sprintf( '|^%s|i', preg_quote( $home_path, '|' ) );
$home_path_regex = sprintf( '!^%s(?:/|$)!i', preg_quote( $home_path, '!' ) );
}

/*
Expand Down
23 changes: 23 additions & 0 deletions tests/phpunit/tests/wp/parseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,27 @@ static function ( $url ) {
$this->wp->parse_request();
$this->assertSame( '', $this->wp->request );
}

/**
* Tests that a requested path starting with the same characters as the home
* path, but not actually inside it, is not stripped as if it were a match.
*
* @ticket 40339
*/
public function test_pathinfo_prefix_matching_home_path_is_not_stripped() {
$this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );

add_filter(
'home_url',
static function () {
return 'http://' . WP_TESTS_DOMAIN . '/wp';
}
);

$_SERVER['PATH_INFO'] = '/wp-json/wc/v1/products';

$this->wp->parse_request();

$this->assertSame( 'wp-json/wc/v1/products', $this->wp->request );
}
}
Loading