diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 85385152c4..58e1b782ef 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -1129,9 +1129,11 @@ class RouteCollection implements RouteCollectionInterface { // Ensure that the param we're inserting matches // the expected param type. + $pos = strpos($from, $pattern); + if (preg_match("|{$pattern}|", $params[$index])) { - $from = str_replace($pattern, $params[$index], $from); + $from = substr_replace($from, $params[$index], $pos, strlen($pattern)); } else { diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php index ea46940d39..a6a6afc7e8 100644 --- a/tests/system/Router/RouteCollectionTest.php +++ b/tests/system/Router/RouteCollectionTest.php @@ -707,6 +707,18 @@ class RouteCollectionTest extends \CIUnitTestCase //-------------------------------------------------------------------- + public function testReverseRouteMatching() + { + $routes = $this->getCollector(); + + $routes->get('test/(:segment)/(:segment)', 'TestController::test/$1/$2', ['as' => 'testRouter']); + + $match = $routes->reverseRoute('testRouter', 1, 2); + + $this->assertEquals('/test/1/2', $match); + } + + public function testAddRedirect() { $routes = $this->getCollector();