Skip to content

Commit ff03eae

Browse files
Merge branch '3.4' into 4.2
* 3.4: (24 commits) Apply php-cs-fixer rule for array_key_exists() [Security] Change FormAuthenticator if condition handles multi-byte characters in autocomplete speed up tests running them without debug flag [Translations] added missing Croatian validators Fix getItems() performance issue with RedisCluster (php-redis) [VarDumper] Keep a ref to objects to ensure their handle cannot be reused while cloning IntegerType: reject submitted non-integer numbers be keen to newcomers [HttpKernel] Fix possible infinite loop of exceptions fixed CS [Validator] Added missing translations for Afrikaans do not validate non-submitted form fields in PATCH requests Update usage example in ArrayInput doc block. [Console] Prevent ArgvInput::getFirstArgument() from returning an option value [Validator] Fixed duplicate UUID fixed CS [EventDispatcher] Fix unknown priority Avoid mutating the Finder when building the iterator [Validator] Add the missing translations for the Greek (el) locale ...
2 parents d5e7ccd + 6b25a86 commit ff03eae

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

Generator/UrlGenerator.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
156156
$message = 'Parameter "{parameter}" for route "{route}" must match "{expected}" ("{given}" given) to generate a corresponding URL.';
157157
foreach ($tokens as $token) {
158158
if ('variable' === $token[0]) {
159-
if (!$optional || !array_key_exists($token[3], $defaults) || null !== $mergedParams[$token[3]] && (string) $mergedParams[$token[3]] !== (string) $defaults[$token[3]]) {
160-
// check requirement
161-
if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]])) {
159+
if (!$optional || !\array_key_exists($token[3], $defaults) || null !== $mergedParams[$token[3]] && (string) $mergedParams[$token[3]] !== (string) $defaults[$token[3]]) {
160+
// check requirement (while ignoring look-around patterns)
161+
if (null !== $this->strictRequirements && !preg_match('#^'.preg_replace('/\(\?(?:=|<=|!|<!)((?:[^()\\\\]+|\\\\.|\((?1)\))*)\)/', '', $token[2]).'$#'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]])) {
162162
if ($this->strictRequirements) {
163163
throw new InvalidParameterException(strtr($message, ['{parameter}' => $token[3], '{route}' => $name, '{expected}' => $token[2], '{given}' => $mergedParams[$token[3]]]));
164164
}
@@ -212,7 +212,8 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
212212
$routeHost = '';
213213
foreach ($hostTokens as $token) {
214214
if ('variable' === $token[0]) {
215-
if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#i'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]])) {
215+
// check requirement (while ignoring look-around patterns)
216+
if (null !== $this->strictRequirements && !preg_match('#^'.preg_replace('/\(\?(?:=|<=|!|<!)((?:[^()\\\\]+|\\\\.|\((?1)\))*)\)/', '', $token[2]).'$#i'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]])) {
216217
if ($this->strictRequirements) {
217218
throw new InvalidParameterException(strtr($message, ['{parameter}' => $token[3], '{route}' => $name, '{expected}' => $token[2], '{given}' => $mergedParams[$token[3]]]));
218219
}

RequestContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public function getParameter($name)
306306
*/
307307
public function hasParameter($name)
308308
{
309-
return array_key_exists($name, $this->parameters);
309+
return \array_key_exists($name, $this->parameters);
310310
}
311311

312312
/**

Route.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public function getOption($name)
327327
*/
328328
public function hasOption($name)
329329
{
330-
return array_key_exists($name, $this->options);
330+
return \array_key_exists($name, $this->options);
331331
}
332332

333333
/**
@@ -396,7 +396,7 @@ public function getDefault($name)
396396
*/
397397
public function hasDefault($name)
398398
{
399-
return array_key_exists($name, $this->defaults);
399+
return \array_key_exists($name, $this->defaults);
400400
}
401401

402402
/**
@@ -481,7 +481,7 @@ public function getRequirement($key)
481481
*/
482482
public function hasRequirement($key)
483483
{
484-
return array_key_exists($key, $this->requirements);
484+
return \array_key_exists($key, $this->requirements);
485485
}
486486

487487
/**

Router.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function setOptions(array $options)
142142
// check option names and live merge, if errors are encountered Exception will be thrown
143143
$invalid = [];
144144
foreach ($options as $key => $value) {
145-
if (array_key_exists($key, $this->options)) {
145+
if (\array_key_exists($key, $this->options)) {
146146
$this->options[$key] = $value;
147147
} else {
148148
$invalid[] = $key;
@@ -164,7 +164,7 @@ public function setOptions(array $options)
164164
*/
165165
public function setOption($key, $value)
166166
{
167-
if (!array_key_exists($key, $this->options)) {
167+
if (!\array_key_exists($key, $this->options)) {
168168
throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
169169
}
170170

@@ -182,7 +182,7 @@ public function setOption($key, $value)
182182
*/
183183
public function getOption($key)
184184
{
185-
if (!array_key_exists($key, $this->options)) {
185+
if (!\array_key_exists($key, $this->options)) {
186186
throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
187187
}
188188

Tests/Generator/UrlGeneratorTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,23 @@ public function testFragmentsCanBeDefinedAsDefaults()
703703
$this->assertEquals('/app.php/testing#fragment', $url);
704704
}
705705

706+
/**
707+
* @dataProvider provideLookAroundRequirementsInPath
708+
*/
709+
public function testLookRoundRequirementsInPath($expected, $path, $requirement)
710+
{
711+
$routes = $this->getRoutes('test', new Route($path, [], ['foo' => $requirement, 'baz' => '.+?']));
712+
$this->assertSame($expected, $this->getGenerator($routes)->generate('test', ['foo' => 'a/b', 'baz' => 'c/d/e']));
713+
}
714+
715+
public function provideLookAroundRequirementsInPath()
716+
{
717+
yield ['/app.php/a/b/b%28ar/c/d/e', '/{foo}/b(ar/{baz}', '.+(?=/b\\(ar/)'];
718+
yield ['/app.php/a/b/bar/c/d/e', '/{foo}/bar/{baz}', '.+(?!$)'];
719+
yield ['/app.php/bar/a/b/bam/c/d/e', '/bar/{foo}/bam/{baz}', '(?<=/bar/).+'];
720+
yield ['/app.php/bar/a/b/bam/c/d/e', '/bar/{foo}/bam/{baz}', '(?<!^).+'];
721+
}
722+
706723
protected function getGenerator(RouteCollection $routes, array $parameters = [], $logger = null)
707724
{
708725
$context = new RequestContext('/app.php');

0 commit comments

Comments
 (0)