From 5044fa4f9f12e00de3d925d4261aedddd8b1dcc5 Mon Sep 17 00:00:00 2001 From: Igor Rozum Date: Wed, 2 Sep 2026 19:24:46 -0400 Subject: [PATCH 1/2] Test: reproduce WP::parse_request() stripping a prefix match of the home path --- tests/phpunit/tests/wp/parseRequest.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/phpunit/tests/wp/parseRequest.php b/tests/phpunit/tests/wp/parseRequest.php index a34a873e892fb..faa35ecb607be 100644 --- a/tests/phpunit/tests/wp/parseRequest.php +++ b/tests/phpunit/tests/wp/parseRequest.php @@ -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 ); + } } From 80d640035627781ab257638dedef0dfb1e2a9ae9 Mon Sep 17 00:00:00 2001 From: Igor Rozum Date: Wed, 2 Sep 2026 19:24:46 -0400 Subject: [PATCH 2/2] Rewrite Rules: Require a path-segment boundary when stripping the home path in WP::parse_request() --- src/wp-includes/class-wp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp.php b/src/wp-includes/class-wp.php index f1664747d4042..a01dbb3faf8b2 100644 --- a/src/wp-includes/class-wp.php +++ b/src/wp-includes/class-wp.php @@ -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, '!' ) ); } /*