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][WIP] Support routes parameters names that are longer than 32 characters #20327

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

Closed

Conversation

fancyweb
Copy link
Contributor

@fancyweb fancyweb commented Oct 27, 2016

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? no
Fixed tickets #8933
License MIT
Doc PR -

Currently, if in one of your route you have a parameter name that exceeds a length of 32 characters, the compilation of the regex fail in the generated UrlMatcher because the subpattern name used for the route parameter is too long (cf #8933).

There is not a single warning about this before you actually try to reach the generated url and you end up with a 500 error.

I fixed this problem by using an alias system that replaces parameters names that are too long by aliases when the route is compiled, and then that replace those aliases by their real names once the request url has been matched with a route.

I need feedback on my idea as this is my first contribution :

…racters

WIP - Tests are missing

fix routes dump
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Oct 27, 2016

Instead of trying to make it work, I suggest trying to make it fail properly. This never worked, so we're not going to break anything.

@Tobion
Copy link
Contributor

Tobion commented Oct 28, 2016

Agree with @nicolas-grekas

@fabpot
Copy link
Member

fabpot commented Nov 10, 2016

@fancyweb Can you work on a fix based on @nicolas-grekas suggestion?

@fancyweb
Copy link
Contributor Author

Ok I will make a new PR. I was waiting for more opinions on this.

What do you think of simply throwing an Exception in the RouteCompiler when the regex is computed ? Maybe new Exception like ParameterNameTooLongException ? I could also update the doc to warn about this.

@fancyweb fancyweb closed this Nov 10, 2016
nicolas-grekas added a commit that referenced this pull request Nov 25, 2016
… be used as a PCRE subpattern name (fancyweb)

This PR was squashed before being merged into the 2.7 branch (closes #20474).

Discussion
----------

[Routing] Fail properly when a route parameter name cannot be used as a PCRE subpattern name

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | symfony/symfony-docs#7139

This is a follow up PR to #20327.

I also decided to improve the current `is_numeric()` check that is done by a truer one. The current limitation is that a PCRE subpattern name must not start with a digit which is different.

Commits
-------

73fbd08 [Routing] Fail properly when a route parameter name cannot be used as a PCRE subpattern name
symfony-splitter pushed a commit to symfony/routing that referenced this pull request Nov 25, 2016
… be used as a PCRE subpattern name (fancyweb)

This PR was squashed before being merged into the 2.7 branch (closes #20474).

Discussion
----------

[Routing] Fail properly when a route parameter name cannot be used as a PCRE subpattern name

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | symfony/symfony-docs#7139

This is a follow up PR to symfony/symfony#20327.

I also decided to improve the current `is_numeric()` check that is done by a truer one. The current limitation is that a PCRE subpattern name must not start with a digit which is different.

Commits
-------

73fbd08 [Routing] Fail properly when a route parameter name cannot be used as a PCRE subpattern name
@ryan-senn
Copy link

Instead of trying to make it work, I suggest trying to make it fail properly. This never worked, so we're not going to break anything.

This seems like a really weak argument to me. Because it never worked, lets not improve anything? There are legitimate reasons to want more than 32 characters, such as prefixes in large code-bases, following conventions etc. Increasing the limit brings nothing but advantages. A quick google search will bring up quite a few results, meaning this is an actual issue that people are facing.

Thanks for your improvement fancyweb, I will use your solution in the meantime.

@sstok
Copy link
Contributor

sstok commented Apr 9, 2017

@ryan-senn If you can provide a good example (actual route paths) it maybe possible this can be reconsidered. Looking at the generated result it doesn't seem to affect code or performance under normal conditions (names <32 chars).

But I would vote for a better naming system as variableAlias1 is not really helpful for debugging 😜 rather something like shortest_possible_name_1 so you can still have an idea were it's related to. And more tests are needed as the PhpDumper as no tests for this specific situation.

@fancyweb
Copy link
Contributor Author

@sstok I actually found this problem with real route paths that are very long because of my own convention that consist of using the full entity name as the placeholder name in my route.

For instance, in one big project I have the entity SupplierMarkingStaticVariablePriceHolder (40 characters).
I would like to use the following route path : /supplier-marking-static-variable-price-holder/{supplierMarkingStaticVariablePriceHolderId}/supplier-marking-static-variable-price/new
But I have to use : /supplier-marking-static-variable-price-holder/{sMStaticVariablePriceHolderId}/supplier-marking-static-variable-price/new

Currently, this project has 619 routes and I would like all of them to follow the same convention for clarity and clean / logic code, but with the 32 characters limit, the convention cannot be respected : it breaks the project logic.

I know that my convention is not THE convention, but as @ryan-senn said, supporting more than 32 characters will only bring advantages.

@sstok
Copy link
Contributor

sstok commented Apr 11, 2017

That seems like a valid use-case, but I'm not able to vote 😜 If performance for the "old" situation is not affected I think it's reasonable to accept this.

@fancyweb fancyweb deleted the unlimited-route-parameter-length branch August 9, 2019 07:12
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.

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