diff --git a/src/PairedRouting.php b/src/PairedRouting.php index 20c52720720..049b889ff24 100644 --- a/src/PairedRouting.php +++ b/src/PairedRouting.php @@ -391,13 +391,16 @@ public function detect_endpoint_in_environment() { continue; } + $paired_url_structure = $this->get_paired_url_structure(); + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $old_path = wp_unslash( $_SERVER[ $var_name ] ); // Because of wp_magic_quotes(). - $new_path = $this->get_paired_url_structure()->remove_endpoint( $old_path ); - if ( $old_path === $new_path ) { + if ( ! $paired_url_structure->has_endpoint( $old_path ) ) { continue; } + $new_path = $paired_url_structure->remove_endpoint( $old_path ); + $this->suspended_environment_variables[ $var_name ] = [ $old_path, $new_path ]; $this->did_request_endpoint = true; diff --git a/tests/php/src/PairedRoutingTest.php b/tests/php/src/PairedRoutingTest.php index 8abdf79742f..42e8d94dcd5 100644 --- a/tests/php/src/PairedRoutingTest.php +++ b/tests/php/src/PairedRoutingTest.php @@ -214,6 +214,12 @@ public function get_data_for_test_paired_requests() { '/', false, ], + 'url_with_empty_query_var' => [ + AMP_Theme_Support::READER_MODE_SLUG, + Option::PAIRED_URL_STRUCTURE_QUERY_VAR, + '/?foo=', + false, + ], 'path_suffix_transitional_mode_amp' => [ AMP_Theme_Support::TRANSITIONAL_MODE_SLUG, Option::PAIRED_URL_STRUCTURE_PATH_SUFFIX, @@ -370,6 +376,10 @@ public function test_detect_endpoint_in_environment() { $_SERVER['REQUEST_URI'] = $this->instance->add_endpoint( '/' ); $this->instance->detect_endpoint_in_environment(); $this->assertTrue( $this->get_private_property( $this->instance, 'did_request_endpoint' ) ); + + $_SERVER['REQUEST_URI'] = '/?foo='; + $this->instance->detect_endpoint_in_environment(); + $this->assertFalse( $this->get_private_property( $this->instance, 'did_request_endpoint' ) ); } /** @return array */