mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Merge pull request #7652 from kenjis/fix-url-to-error-msg
fix: `url_to()` error message
This commit is contained in:
commit
d7cda9308f
@ -1239,6 +1239,11 @@ class RouteCollection implements RouteCollectionInterface
|
||||
// Build our resulting string, inserting the $params in
|
||||
// the appropriate places.
|
||||
foreach ($matches[0] as $index => $pattern) {
|
||||
if (! isset($params[$index])) {
|
||||
throw new InvalidArgumentException(
|
||||
'Missing argument for "' . $pattern . '" in route "' . $from . '".'
|
||||
);
|
||||
}
|
||||
if (! preg_match('#^' . $pattern . '$#u', $params[$index])) {
|
||||
throw RouterException::forInvalidParameterType();
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ use CodeIgniter\HTTP\URI;
|
||||
use CodeIgniter\Router\Exceptions\RouterException;
|
||||
use CodeIgniter\Test\CIUnitTestCase;
|
||||
use Config\App;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @backupGlobals enabled
|
||||
@ -900,4 +901,20 @@ final class MiscUrlTest extends CIUnitTestCase
|
||||
url_to('path-to', 'string', 13, 'en')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://github.com/codeigniter4/CodeIgniter4/issues/7651
|
||||
*/
|
||||
public function testUrlToMissingArgument()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Missing argument for "([a-zA-Z]+)" in route "([a-zA-Z]+)/login".');
|
||||
|
||||
$routes = Services::routes();
|
||||
$routes->group('(:alpha)', static function ($routes) {
|
||||
$routes->match(['get'], 'login', 'Common\LoginController::loginView', ['as' => 'loginURL']);
|
||||
});
|
||||
|
||||
url_to('loginURL');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user