diff --git a/VERSION.txt b/VERSION.txt index 994f0ca6e73..4816ad91d9b 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -16,4 +16,4 @@ // @license https://opensource.org/licenses/mit-license.php MIT License // +--------------------------------------------------------------------------------------------+ // //////////////////////////////////////////////////////////////////////////////////////////////////// -4.5.9 +4.5.10 diff --git a/src/Routing/RouteCollection.php b/src/Routing/RouteCollection.php index 2f3988cf601..c91e5ba9e6c 100644 --- a/src/Routing/RouteCollection.php +++ b/src/Routing/RouteCollection.php @@ -225,7 +225,7 @@ public function parseRequest(ServerRequestInterface $request): array } if ($uri->getQuery()) { parse_str($uri->getQuery(), $queryParameters); - $r['?'] = $queryParameters; + $r['?'] = array_merge($r['?'] ?? [], $queryParameters); } return $r; diff --git a/tests/TestCase/Routing/RouteCollectionTest.php b/tests/TestCase/Routing/RouteCollectionTest.php index 692b209c7f8..096f960e2c8 100644 --- a/tests/TestCase/Routing/RouteCollectionTest.php +++ b/tests/TestCase/Routing/RouteCollectionTest.php @@ -24,6 +24,7 @@ use Cake\Routing\RouteCollection; use Cake\TestSuite\TestCase; use RuntimeException; +use TestApp\Routing\Route\AddQueryParamRoute; class RouteCollectionTest extends TestCase { @@ -138,8 +139,8 @@ public function testParse(): void $this->assertEquals($expected, $result); }); } - /** + * Test parse() handling query strings. */ public function testParseQueryString(): void @@ -352,6 +353,31 @@ public function testParseRequestQueryString(): void $this->assertEquals($expected, $result); } + /** + * Test parseRequest() handling query strings. + */ + public function testParseRequestQueryStringFromRoute(): void + { + $routes = new RouteBuilder($this->collection, '/'); + $routes->connect( + '/test', + ['controller' => 'Articles', 'action' => 'view'], + ['routeClass' => AddQueryParamRoute::class], + ); + $request = new ServerRequest(['url' => '/test?y=2']); + $result = $this->collection->parseRequest($request); + unset($result['_route']); + $expected = [ + 'controller' => 'Articles', + 'action' => 'view', + 'pass' => [], + 'plugin' => null, + '_matchedRoute' => '/test', + '?' => ['x' => '1', 'y' => '2'], + ]; + $this->assertEquals($expected, $result); + } + /** * Test parseRequest() checks host conditions */ diff --git a/tests/test_app/TestApp/Routing/Route/AddQueryParamRoute.php b/tests/test_app/TestApp/Routing/Route/AddQueryParamRoute.php new file mode 100644 index 00000000000..06e8075e7c9 --- /dev/null +++ b/tests/test_app/TestApp/Routing/Route/AddQueryParamRoute.php @@ -0,0 +1,20 @@ +