You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug #20474 [Routing] Fail properly when a route parameter name cannot 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
thrownew \DomainException(sprintf('Variable name "%s" cannot be numeric in route pattern "%s". Please use a different name.', $varName, $pattern));
106
+
// A PCRE subpattern name must start with a non-digit. Also a PHP variable cannot start with a digit so the
107
+
// variable would not be usable as a Controller action argument.
108
+
if (preg_match('/^\d/', $varName)) {
109
+
thrownew \DomainException(sprintf('Variable name "%s" cannot start with a digit in route pattern "%s". Please use a different name.', $varName, $pattern));
100
110
}
101
111
if (in_array($varName, $variables)) {
102
112
thrownew \LogicException(sprintf('Route pattern "%s" cannot reference variable name "%s" more than once.', $pattern, $varName));
103
113
}
104
114
115
+
if (strlen($varName) > self::VARIABLE_MAXIMUM_LENGTH) {
116
+
thrownew \DomainException(sprintf('Variable name "%s" cannot be longer than %s characters in route pattern "%s". Please use a shorter name.', $varName, self::VARIABLE_MAXIMUM_LENGTH, $pattern));
0 commit comments