8000 bug #27498 [Routing] Don't reorder past variable-length placeholders … · symfony/symfony@2521e7b · GitHub
[go: up one dir, main page]

Skip to content

Commit 2521e7b

Browse files
bug #27498 [Routing] Don't reorder past variable-length placeholders (nanocom, nicolas-grekas)
This PR was merged into the 4.1 branch. Discussion ---------- [Routing] Don't reorder past variable-length placeholders | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | no | Fixed tickets | #27491 | License | MIT Commits ------- 44616d9 [Router] regression when matching a route 7a750d4 [Routing] Don't reorder past variable-length placeholders
2 parents 7605706 + 44616d9 commit 2521e7b

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed

src/Symfony/Component/Routing/Matcher/Dumper/StaticPrefixCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private function getCommonPrefix(string $prefix, string $anotherPrefix): array
176176
break;
177177
}
178178
$subPattern = substr($prefix, $i, $j - $i);
179-
if ($prefix !== $anotherPrefix && !preg_match('/^\(\[[^\]]++\]\+\+\)$/', $subPattern) && !preg_match('{(?<!'.$subPattern.')}', '')) {
179+
if ($prefix !== $anotherPrefix && !preg_match('{(?<!'.$subPattern.')}', '')) {
180180
// sub-patterns of variable length are not considered as common prefixes because their greediness would break in-order matching
181181
break;
182182
}

src/Symfony/Component/Routing 10000 /Tests/Fixtures/dumper/url_matcher12.php

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,13 @@ public function match($rawPathinfo)
2929
$matchedPathinfo = $pathinfo;
3030
$regexList = array(
3131
0 => '{^(?'
32-
.'|/abc([^/]++)/(?'
33-
.'|1(?'
34-
.'|(*:27)'
35-
.'|0(?'
36-
.'|(*:38)'
37-
.'|0(*:46)'
38-
.')'
39-
.')'
40-
.'|2(?'
41-
.'|(*:59)'
42-
.'|0(?'
43-
.'|(*:70)'
44-
.'|0(*:78)'
45-
.')'
46-
.')'
32+
.'|/abc(?'
33+
.'|([^/]++)/1(*:24)'
34+
.'|([^/]++)/2(*:41)'
35+
.'|([^/]++)/10(*:59)'
36+
.'|([^/]++)/20(*:77)'
37+
.'|([^/]++)/100(*:96)'
38+
.'|([^/]++)/200(*:115)'
4739
.')'
4840
.')$}sD',
4941
);
@@ -53,12 +45,12 @@ public function match($rawPathinfo)
5345
switch ($m = (int) $matches['MARK']) {
5446
default:
5547
$routes = array(
56-
27 => array(array('_route' => 'r1'), array('foo'), null, null),
57-
38 => array(array('_route' => 'r10'), array('foo'), null, null),
58-
46 => array(array('_route' => 'r100'), array('foo'), null, null),
59-
59 => array(array('_route' => 'r2'), array('foo'), null, null),
60-
70 => array(array('_route' => 'r20'), array('foo'), null, null),
61-
78 => array(array('_route' => 'r200'), array('foo'), null, null),
48+
24 => array(array('_route' => 'r1'), array('foo'), null, 8000 null),
49+
41 => array(array('_route' => 'r2'), array('foo'), null, null),
50+
59 => array(array('_route' => 'r10'), array('foo'), null, null),
51+
77 => array(array('_route' => 'r20'), array('foo'), null, null),
52+
96 => array(array('_route' => 'r100'), array('foo'), null, null),
53+
115 => array(array('_route' => 'r200'), array('foo'), null, null),
6254
);
6355

6456
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
@@ -84,7 +76,7 @@ public function match($rawPathinfo)
8476
return $ret;
8577
}
8678

87-
if (78 === $m) {
79+
if (115 === $m) {
8880
break;
8981
}
9082
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));

src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,18 @@ public function testMatchRegression()
245245
}
246246
}
247247

248+
public function testMultipleParams()
249+
{
250+
$coll = new RouteCollection();
251+
$coll->add('foo1', new Route('/foo/{a}/{b}'));
252+
$coll->add('foo2', new Route('/foo/{a}/test/test/{b}'));
253+
$coll->add('foo3', new Route('/foo/{a}/{b}/{c}/{d}'));
254+
255+
$route = $this->getUrlMatcher($coll)->match('/foo/test/test/test/bar')['_route'];
256+
257+
$this->assertEquals('foo2', $route);
258+
}
259+
248260
public function testDefaultRequirementForOptionalVariables()
249261
{
250262
$coll = new RouteCollection();

0 commit comments

Comments
 (0)
0