Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route Parameters Regular Expression Constraints error since PHP 7.3 #27340

Closed
roko91 opened this issue Jan 28, 2019 · 4 comments
Closed

Route Parameters Regular Expression Constraints error since PHP 7.3 #27340

roko91 opened this issue Jan 28, 2019 · 4 comments

Comments

@roko91
Copy link

roko91 commented Jan 28, 2019

  • Laravel Version: 5.7.22
  • PHP Version: 7.3.1
  • Database Driver & Version: MySQL 5.7.24

Description:

For my Route Parameters Regular Expression Constraints I get the following error since PHP 7.3:

ErrorException thrown with message "preg_match(): Compilation failed: invalid range in character class at offset 55"

Stacktrace:
32 ErrorException in .../vendor/laravel/framework/src/Illuminate/Routing/Matching/UriValidator.php:21
31 preg_match in .../vendor/laravel/framework/src/Illuminate/Routing/Matching/UriValidator.php:21
30 Illuminate\Routing\Matching\UriValidator:matches in .../vendor/laravel/framework/src/Illuminate/Routing/Route.php:275
29 Illuminate\Routing\Route:matches in .../vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:197
28 Illuminate\Routing\RouteCollection:Illuminate\Routing{closure} in .../vendor/laravel/framework/src/Illuminate/Support/Arr.php:175
27 call_user_func in .../vendor/laravel/framework/src/Illuminate/Support/Arr.php:175
26 Illuminate\Support\Arr:first in .../vendor/laravel/framework/src/Illuminate/Support/Collection.php:758
25 Illuminate\Support\Collection:first in .../vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:198
24 Illuminate\Routing\RouteCollection:matchAgainstRoutes in .../vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:164
23 Illuminate\Routing\RouteCollection:match in .../vendor/laravel/framework/src/Illuminate/Routing/Router.php:636
22 Illuminate\Routing\Router:findRoute in .../vendor/laravel/framework/src/Illuminate/Routing/Router.php:625
21 Illuminate\Routing\Router:dispatchToRoute in .../vendor/laravel/framework/src/Illuminate/Routing/Router.php:614
20 Illuminate\Routing\Router:dispatch in .../vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:176
19 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http{closure} in .../vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
18 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in .../vendor/fideloper/proxy/src/TrustProxies.php:57
17 Fideloper\Proxy\TrustProxies:handle in .../vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
16 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in .../vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
15 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in .../vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:31
14 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in .../vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
13 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in .../vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
12 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in .../vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:31
11 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in .../vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
10 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in .../vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
9 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in .../vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27
8 Illuminate\Foundation\Http\Middleware\ValidatePostSize:handle in .../vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
7 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in .../vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
6 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in .../vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:62
5 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in .../vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
4 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in .../vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
3 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in .../vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:104
2 Illuminate\Pipeline\Pipeline:then in .../vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:151
1 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in .../vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116
0 Illuminate\Foundation\Http\Kernel:handle in .../public/index.php:55

Arguments for 31 in the stack trace:

  1. "#^/(?Pvideo|text)-tutorials(?:/(?P[\w\d-]+)(?:/(?P[\w\d-]+))?)?$#sDu"
  2. "/"

I believe this is caused by the following change in the PCRE extension:
PHP: Other Changes

The PCRE extension has been upgraded to PCRE2, which may cause minor behavioral changes (for instance, character ranges in classes are now more strictly interpreted), and augments the existing regular expression syntax.

Steps To Reproduce:

Create a similar route:
Route::get('{type}-tutorials/{location?}/{page?}', 'TutorialController@index')->where([
'type' => 'video|text',
'location' => '[\w\d-]+',
'page' => '[\w\d-
]+'
]);

@staudenmeir
Copy link
Contributor

Similar issue: #25194

But in your case, I can't reproduce the error. I also don't see the invalid range.

BTW: GitHub interprets parts of the pattern as HTML, this is the actual one:

#^/(?P<type>video|text)\-tutorials(?:/(?P<location>[\w\d-]+)(?:/(?P<page>[\w\d-]+))?)?$#sDu

@driesvints
Copy link
Member

@staudenmeir shouldn't the patterns above escape the - sign like in your PR?

'[\w\d\-]+',

@staudenmeir
Copy link
Contributor

staudenmeir commented Jan 28, 2019

@driesvints AFAIK, that's only necessary if the hyphen is followed by another character:

preg_match('/[a-]/', '');   // Works.
preg_match('/[a-.]/', '');  // Doesn't work.
preg_match('/[a\-.]/', ''); // Works.

@driesvints
Copy link
Member

Okay.

@roko91 since we can't reproduce this I suggest you try on a support channel first. If you can actually identify this as a bug, feel free to report back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants