Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Routing] fix matching host patterns, utf8 prefixes and non-capturing groups #27511

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

Merged
merged 1 commit into from
Jun 10, 2018

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Jun 6, 2018

Q A
Branch? 4.1
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #27448, #27461, #27504, #27512
License MIT
Doc PR -

@rmsint
Copy link

rmsint commented Jun 6, 2018

I ran into the preg_match(): Compilation failed: ... unmatched parentheses ... error and tried this fix. I could narrow it down to a utf8 route:

/**
 * @Route(
 *     "/file/{filename}",
 *     name = "file_download",
 *     requirements = { "filename": ".+" },
 *     options = { "utf8": true }
 * )
 * @Method("GET")
 */
public function download($filename, LocalFileSystem $localFileSystem)
{
  // ..
}

Similar as https://symfony.com/blog/new-in-symfony-3-2-unicode-routing-support

As soon as I remove the options = { "utf8": true } from the route my tests pass again and the route matcher does not throw the preg_match(): ... unmatched parentheses anymore.

@nicolas-grekas
Copy link
Member Author

@rmsint see #27504, that's the issue you're experiencing. I'll add a fix for it here soon.

@rmsint
Copy link

rmsint commented Jun 6, 2018

@nicolas-grekas yes exactly, I noticed you pointed there to this fix. Thanks!

@nicolas-grekas nicolas-grekas force-pushed the route-fix-host branch 2 times, most recently from b01e533 to 36e4f29 Compare June 6, 2018 16:25
@nicolas-grekas
Copy link
Member Author

PR is ready, sorry about the huge diff, its fixtures...

@@ -187,6 +185,11 @@ private function getCommonPrefix(string $prefix, string $anotherPrefix): array
}
}
restore_error_handler();
if ($i < $end && 0b10 === (\ord($prefix[$i]) >> 6) && preg_match('//u', $prefix.' '.$anotherPrefix)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a comment here explaining what that snippet of code do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment added

@nicolas-grekas
Copy link
Member Author

Status: needs review

@fabpot
Copy link
Member

fabpot commented Jun 10, 2018

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 465b15c into symfony:4.1 Jun 10, 2018
fabpot added a commit that referenced this pull request Jun 10, 2018
…n-capturing groups (nicolas-grekas)

This PR was merged into the 4.1 branch.

Discussion
----------

[Routing] fix matching host patterns, utf8 prefixes and non-capturing groups

| Q             | A
| ------------- | ---
| Branch?       | 4.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27448, #27461, #27504, #27512
| License       | MIT
| Doc PR        | -

Commits
-------

465b15c [Routing] fix matching host patterns, utf8 prefixes and non-capturing groups
@nicolas-grekas nicolas-grekas deleted the route-fix-host branch June 10, 2018 19:14
@teohhanhui
Copy link
Contributor

Shouldn't we consider using a proper parser for the Routing component? Similar to: https://github.com/rcs/route-parser

https://github.com/rcs/route-parser/blob/12f4077798fbeab39e1abb8b2a4ad2fac1919809/lib/route/compiled-grammar.js

@stof
Copy link
Member

stof commented Jun 19, 2018

@teohhanhui we are already parsing routes properly, and compiling them to a regex each (which is what this route-parser is doing) is battle-tested in symfony since many years.

the hard thing here is that Symfony 4.1 is now generating only a few regexes combining routes together to make matching much faster. And the new logic is not yet as battle-tested for all edge-cases (and the fact that we combine routes creates much more weird cases than when matching them separately, as we need to think about how the cases interact together).
The route-parser you linked too will match a single route, not a full collection of routes to find the matching one.

@teohhanhui
Copy link
Contributor

teohhanhui commented Jun 19, 2018

Sorry, I must have misunderstood. Because I cannot find any parser in the Symfony Routing component:
https://github.com/symfony/routing/search?q=parse&unscoped_q=parse

like I could in Twig:
https://github.com/twigphp/Twig/search?q=parse&unscoped_q=parse

or the Symfony ExpressionLanguage component:
https://github.com/symfony/expression-language/search?q=parse&unscoped_q=parse

@fabpot fabpot mentioned this pull request Jun 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.