preg_match(): Compilation failed in Shield and Myth/Auth |
Hello guys!
If anyone knows this please help. I am using apache 2.4.51, PHP 8.0.12 on Microsoft Windows 11 64 bit operating system and using Codeigniter 4.3.1 to test Shield and Myth/Auth. It worked fine until everything used locale(language). However, after applying locale, there is no problem in get, but the following error occurs in post. Of course, the data transmitted to the database is not entered. browser error message ============================== ErrorException preg_match(): Compilation failed: unmatched closing parenthesis at offset 7 SYSTEMPATH\Router\Router.php at line 418 411 412 // Are we dealing with a locale? 413 if (strpos($routeKey, '{locale}') !== false) { 414 $routeKey = str_replace('{locale}', '[^/]+', $routeKey); 415 } 416 417 // Does the RegEx match? 418 if (preg_match('#^' . $routeKey . '$#u', $uri, $matches)) { 419 // Is this route supposed to redirect to another? 420 if ($this->collection->isRedirect($routeKey)) { 421 // replacing matched route groups with references: post/([0-9]+) -> post/$1 422 $redirectTo = preg_replace_callback('/(\([^\(]+\))/', static function () { 423 static $i = 1; 424 425 return '$' . $i++; {PHP internal code} — CodeIgniter\Debug\Exceptions->errorHandler ( arguments ) SYSTEMPATH\Router\Router.php : 418 — preg_match() SYSTEMPATH\Router\Router.php : 181 — CodeIgniter\Router\Router->checkRoutes ( arguments ) 174 $uri = urldecode($uri); 175 176 // Restart filterInfo 177 $this->filterInfo = null; 178 $this->filtersInfo = []; 179 180 // Checks defined routes 181 if ($this->checkRoutes($uri)) { 182 if ($this->collection->isFiltered($this->matchedRoute[0])) { 183 $multipleFiltersEnabled = config('Feature')->multipleFilters ?? false; 184 if ($multipleFiltersEnabled) { 185 $this->filtersInfo = $this->collection->getFiltersForRoute($this->matchedRoute[0]); 186 } else { 187 // for backward compatibility 188 $this->filterInfo = $this->collection->getFilterForRoute($this->matchedRoute[0]); SYSTEMPATH\CodeIgniter.php : 815 — CodeIgniter\Router\Router->handle ( arguments ) 808 $path = $this->determinePath(); 809 810 $this->benchmark->stop('bootstrap'); 811 $this->benchmark->start('routing'); 812 813 ob_start(); 814 815 $this->controller = $this->router->handle($path); 816 $this->method = $this->router->methodName(); 817 818 // If a {locale} segment was matched in the final route, 819 // then we need to set the correct locale on our Request. 820 if ($this->router->hasLocale()) { 821 $this->request->setLocale($this->router->getLocale()); 822 } SYSTEMPATH\CodeIgniter.php : 449 — CodeIgniter\CodeIgniter->tryToRouteIt ( arguments ) 442 * 443 * @deprecated $returnResponse is deprecated. 444 */ 445 protected function handleRequest(?RouteCollectionInterface $routes, Cache $cacheConfig, bool $returnResponse = false) 446 { 447 $this->returnResponse = $returnResponse; 448 449 $routeFilter = $this->tryToRouteIt($routes); 450 451 $uri = $this->determinePath(); 452 453 if ($this->enableFilters) { 454 // Start up the filters 455 $filters = Services::filters(); 456 SYSTEMPATH\CodeIgniter.php : 368 — CodeIgniter\CodeIgniter->handleRequest ( arguments ) 361 $this->response->send(); 362 $this->callExit(EXIT_SUCCESS); 363 364 return; 365 } 366 367 try { 368 return $this->handleRequest($routes, $cacheConfig, $returnResponse); 369 } catch (RedirectException $e) { 370 $logger = Services::logger(); 371 $logger->info('REDIRECTED ROUTE at ' . $e->getMessage()); 372 373 // If the route is a 'redirect' route, it throws 374 // the exception with the $to as the message 375 $this->response->redirect(base_url($e->getMessage()), 'auto', $e->getCode()); FCPATH\index.php : 67 — CodeIgniter\CodeIgniter->run () 60 *--------------------------------------------------------------- 61 * LAUNCH THE APPLICATION 62 *--------------------------------------------------------------- 63 * Now that everything is setup, it's time to actually fire 64 * up the engines and make this app do its thang. 65 */ 66 67 $app->run(); ============================== Error message in log file ============================== CRITICAL - (Time) --> preg_match(): Compilation failed: unmatched closing parenthesis at offset 7 in SYSTEMPATH\Router\Router.php on line 418. 1 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'preg_match(): Compilation failed: unmatched closing parenthesis at offset 7', 'SYSTEMPATH\\Router\\Router.php', 418) 2 SYSTEMPATH\Router\Router.php(418): preg_match('#^Search)$#u', 'en/auth/register', null) 3 SYSTEMPATH\Router\Router.php(181): CodeIgniter\Router\Router->checkRoutes('en/auth/register') 4 SYSTEMPATH\CodeIgniter.php(815): CodeIgniter\Router\Router->handle('en/auth/register') 5 SYSTEMPATH\CodeIgniter.php(449): CodeIgniter\CodeIgniter->tryToRouteIt(Object(CodeIgniter\Router\RouteCollection)) 6 SYSTEMPATH\CodeIgniter.php(368): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false) 7 FCPATH\index.php(67): CodeIgniter\CodeIgniter->run() ==============================
It seems your route is invalid.
Check your routes. php spark routes
@dolsorina Are you trying to access routes {locale}/login as below?
eg: http://localhost:8080/index.php/fa/auth/a/show http://localhost:8080/index.php/ja/auth/a/show If yes, you should know that currently Shield does not support this method. I want to know if you really need this possibility or not. Because in order to support this method, we have to make changes in the file Auth class LoginController and ... Shield. (02-21-2023, 03:21 AM)kenjis Wrote: It seems your route is invalid. Thank you very much. I'm still learning about CodeIgniter. >php spark routes There was no problem before using Shield or Myth/Auth, but the problem occurred when using the locale as follows. App/Configuration/Routes.php /*=================================*/ $routes->group('{locale}', static function ($routes) { service('auth')->routes($routes); }); /*=================================*/ Of course there is no problem with the routing above. This problem was caused by my incorrect use of regular expressions in other route rules. (02-21-2023, 09:03 AM)datamweb Wrote: @dolsorina Are you trying to access routes {locale}/login as below?Thank you very much for your interest and reply. The problem was caused by using regular expressions that violate routing rules.
@datamweb could you please advise in which version of CodeIgniter 4 that this bug was fixed?
I'm currently facing issue with a downgraded project to 4.4.7 from 4.5.5 due to hosting constraints max PHP version to be PHP 7.4.33 CodeIgniter Wizard (CRUD code generator for Mac) instantly scaffolds Bootstrap-based web applications with an administrative interface (admin templates include Bootstrap5) |
Welcome Guest, Not a member yet? Register Sign In |