Fix router matching for underscored route params

This commit is contained in:
Jeppe Bundgaard
2026-06-30 13:10:06 +02:00
parent c6cf953ede
commit f7a4126718
2 changed files with 17 additions and 1 deletions
+1 -1
View File
@@ -89,7 +89,7 @@ class router
}
// Regex
$route = str_replace('/', '\/', $route);
$route = preg_replace('/{[a-zA-Z0-9]+}/', '([a-zA-Z0-9]+)', $route);
$route = preg_replace('/{[a-zA-Z0-9_]+}/', '([a-zA-Z0-9]+)', $route);
if (preg_match('/^' . $route . '$/', $this->url)) {
return true;
}
@@ -0,0 +1,16 @@
<?php
use classes\router;
it('matches dynamic route parameter names containing underscores', function (): void {
$_SERVER['REQUEST_URI'] = '/modules/self-serve/lane/hardware/batch/916cdba1981e52f3dc728ea06fc39cf0';
$_SERVER['REQUEST_METHOD'] = 'GET';
$router = new router();
$matcher = new ReflectionMethod(router::class, 'doesRouteMatchCurrent');
expect($matcher->invoke(
$router,
'/modules/self-serve/lane/hardware/batch/{batch_id}'
))->toBeTrue();
});