diff --git a/src/Router/UrlGenerator.php b/src/Router/UrlGenerator.php index 5c6f4a847..7268b4637 100644 --- a/src/Router/UrlGenerator.php +++ b/src/Router/UrlGenerator.php @@ -326,7 +326,7 @@ public static function buildStr(array $query, string $prefix = '', $argSeparator if ($i === $k) { if ($prefix) { // Make sure the key is setup for array values - if (Str::endsWith($prefix, '[]')) { + if (Str::endsWith($prefix, ']')) { $key = $prefix; } else { $key = "{$prefix}[]"; diff --git a/tests/Router/UrlGeneratorTest.php b/tests/Router/UrlGeneratorTest.php index ada08285b..5ec7a9330 100644 --- a/tests/Router/UrlGeneratorTest.php +++ b/tests/Router/UrlGeneratorTest.php @@ -516,9 +516,13 @@ public function testQueryArgsArrayMatchLaravel() $checkUrlsOnBoth = [ // Non url-encoded 'https://www.example.com/path?array[]=v1&array[]=v2', + 'https://www.example.com/path?array[0]=v1&array[1]=v2', + 'https://www.example.com/path?array[k1]=v1&array[k2]=v2', // Already url-encoded 'https://www.example.com/path?array%5B%5D=v1&array%5B%5D=v2', + 'https://www.example.com/path?array%5B0%5D=v1&array%5B1%5D=v2', + 'https://www.example.com/path?array%5Bk1%5D=v1&array%5Bk2%5D=v2', ]; foreach ($checkUrlsOnBoth as $url) {