Skip to content

Commit 03ec3ff

Browse files
committed
refactor: use \A and \z
It is better to use always \A and \z if you try to check a string. Because `$` matches the end of a line, and matches a newline charactor.
1 parent 1c65aa1 commit 03ec3ff

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

system/Router/Router.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ protected function checkRoutes(string $uri): bool
448448
}, is_array($handler) ? key($handler) : $handler);
449449

450450
throw new RedirectException(
451-
preg_replace('#^' . $routeKey . '$#u', $redirectTo, $uri),
451+
preg_replace('#\A' . $routeKey . '\z#u', $redirectTo, $uri),
452452
$this->collection->getRedirectCode($routeKey)
453453
);
454454
}
@@ -502,7 +502,7 @@ protected function checkRoutes(string $uri): bool
502502
}
503503

504504
// Using back-references
505-
$handler = preg_replace('#^' . $routeKey . '$#u', $handler, $uri);
505+
$handler = preg_replace('#\A' . $routeKey . '\z#u', $handler, $uri);
506506
}
507507

508508
$this->setRequest(explode('/', $handler));

0 commit comments

Comments
 (0)