Skip to content

Commit a25082b

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

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
@@ -569,7 +569,7 @@ protected function checkRoutes(string $uri): bool
569569
*/
570570
private function replaceBackReferences(string $input, array $matches): string
571571
{
572-
$pattern = '/\$([1-' . count($matches) . '])/u';
572+
$pattern = '/\$([1-9][0-9]*)/u';
573573

574574
return preg_replace_callback(
575575
$pattern,

‎tests/system/Router/RouterTest.php‎

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

1038+
public function testMultipleSegmentsParamTrueWithTenPlaceholders(): void
1039+
{
1040+
$routingConfig = new Routing();
1041+
$routingConfig->multipleSegmentsOneParam = true;
1042+
Factories::injectMock('config', Routing::class, $routingConfig);
1043+
1044+
$this->createRouteCollection($routingConfig);
1045+
$this->collection->get(
1046+
'(:segment)/(:segment)/(:segment)/(:segment)/(:segment)/(:segment)/(:segment)/(:segment)/(:segment)/(:segment)',
1047+
'Catalog::lookup/$1/$2/$3/$4/$5/$6/$7/$8/$9/$10',
1048+
);
1049+
$router = new Router($this->collection, $this->request);
1050+
1051+
$router->handle('a/b/c/d/e/f/g/h/i/j');
1052+
1053+
$this->assertSame('\Catalog', $router->controllerName());
1054+
$this->assertSame('lookup', $router->methodName());
1055+
$this->assertSame(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'], $router->params());
1056+
}
1057+
10381058
public function testLogsRouteAttributeInstantiationFailureWithContext(): void
10391059
{
10401060
$collection = clone $this->collection;

0 commit comments

Comments
 (0)