Skip to content

Commit e83f07b

Browse files
committed
fix(Router): fix back-reference regex in replaceBackReferences() for 9+ placeholders
1 parent 59e5eea commit e83f07b

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎system/Router/Router.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ protected function checkRoutes(string $uri): bool
565565
*/
566566
private function replaceBackReferences(string $input, array $matches): string
567567
{
568-
$pattern = '/\$([1-' . count($matches) . '])/u';
568+
$pattern = '/\$([1-9][0-9]*)/u';
569569

570570
return preg_replace_callback(
571571
$pattern,

‎tests/system/Router/RouterTest.php‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,26 @@ public function testRoutePlaceholderAnyWithMultipleSegmentsParamTrue(): void
10091009
$this->assertSame(['123/456'], $router->params());
10101010
}
10111011

1012+
public function testMultipleSegmentsParamTrueWithTenPlaceholders(): void
1013+
{
1014+
$routingConfig = new Routing();
1015+
$routingConfig->multipleSegmentsOneParam = true;
1016+
Factories::injectMock('config', Routing::class, $routingConfig);
1017+
1018+
$this->createRouteCollection($routingConfig);
1019+
$this->collection->get(
1020+
'(:segment)/(:segment)/(:segment)/(:segment)/(:segment)/(:segment)/(:segment)/(:segment)/(:segment)/(:segment)',
1021+
'Catalog::lookup/$1/$2/$3/$4/$5/$6/$7/$8/$9/$10',
1022+
);
1023+
$router = new Router($this->collection, $this->request);
1024+
1025+
$router->handle('a/b/c/d/e/f/g/h/i/j');
1026+
1027+
$this->assertSame('\Catalog', $router->controllerName());
1028+
$this->assertSame('lookup', $router->methodName());
1029+
$this->assertSame(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'], $router->params());
1030+
}
1031+
10121032
public function testLogsRouteAttributeInstantiationFailureWithContext(): void
10131033
{
10141034
$collection = clone $this->collection;

0 commit comments

Comments
 (0)