Skip to content

Commit fdeff27

Browse files
author
Robin Chalas
committed
Merge branch '2.8' into 3.4
* 2.8: [Intl] Fixed the broken link [Routing] Fix trailing slash redirection for non-safe verbs [Debug] Fix bad registration of exception handler, leading to mem leak [Form] Fixed empty data on expanded ChoiceType and FileType
2 parents 235d017 + 722db7a commit fdeff27

13 files changed

+292
-87
lines changed

Matcher/Dumper/PhpMatcherDumper.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,14 @@ public function match(\$rawPathinfo)
102102
\$pathinfo = rawurldecode(\$rawPathinfo);
103103
\$trimmedPathinfo = rtrim(\$pathinfo, '/');
104104
\$context = \$this->context;
105-
\$request = \$this->request;
105+
\$request = \$this->request ?: \$this->createRequest(\$pathinfo);
106106
\$requestMethod = \$canonicalMethod = \$context->getMethod();
107107
\$scheme = \$context->getScheme();
108108
109109
if ('HEAD' === \$requestMethod) {
110110
\$canonicalMethod = 'GET';
111111
}
112112
113-
114113
$code
115114
116115
throw 0 < count(\$allow) ? new MethodNotAllowedException(array_unique(\$allow)) : new ResourceNotFoundException();
@@ -361,7 +360,11 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
361360

362361
if ($hasTrailingSlash) {
363362
$code .= <<<EOF
364-
if (substr(\$pathinfo, -1) !== '/') {
363+
if ('/' === substr(\$pathinfo, -1)) {
364+
// no-op
365+
} elseif (!in_array(\$this->context->getMethod(), array('HEAD', 'GET'))) {
366+
goto $gotoname;
367+
} else {
365368
return array_replace(\$ret, \$this->redirect(\$rawPathinfo.'/', '$name'));
366369
}
367370
@@ -391,7 +394,7 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
391394
}
392395
$code .= " }\n";
393396

394-
if ($methods) {
397+
if ($methods || $hasTrailingSlash) {
395398
$code .= " $gotoname:\n";
396399
}
397400

Tests/Fixtures/dumper/url_matcher0.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ public function match($rawPathinfo)
2121
$pathinfo = rawurldecode($rawPathinfo);
2222
$trimmedPathinfo = rtrim($pathinfo, '/');
2323
$context = $this->context;
24-
$request = $this->request;
24+
$request = $this->request ?: $this->createRequest($pathinfo);
2525
$requestMethod = $canonicalMethod = $context->getMethod();
2626
$scheme = $context->getScheme();
2727

2828
if ('HEAD' === $requestMethod) {
2929
$canonicalMethod = 'GET';
3030
}
3131

32-
3332
if ('/' === $pathinfo) {
3433
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
3534
}

Tests/Fixtures/dumper/url_matcher1.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ public function match($rawPathinfo)
2121
$pathinfo = rawurldecode($rawPathinfo);
2222
$trimmedPathinfo = rtrim($pathinfo, '/');
2323
$context = $this->context;
24-
$request = $this->request;
24+
$request = $this->request ?: $this->createRequest($pathinfo);
2525
$requestMethod = $canonicalMethod = $context->getMethod();
2626
$scheme = $context->getScheme();
2727

2828
if ('HEAD' === $requestMethod) {
2929
$canonicalMethod = 'GET';
3030
}
3131

32-
3332
if (0 === strpos($pathinfo, '/foo')) {
3433
// foo
3534
if (preg_match('#^/foo/(?P<bar>baz|symfony)$#s', $pathinfo, $matches)) {

Tests/Fixtures/dumper/url_matcher2.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ public function match($rawPathinfo)
2121
$pathinfo = rawurldecode($rawPathinfo);
2222
$trimmedPathinfo = rtrim($pathinfo, '/');
2323
$context = $this->context;
24-
$request = $this->request;
24+
$request = $this->request ?: $this->createRequest($pathinfo);
2525
$requestMethod = $canonicalMethod = $context->getMethod();
2626
$scheme = $context->getScheme();
2727

2828
if ('HEAD' === $requestMethod) {
2929
$canonicalMethod = 'GET';
3030
}
3131

32-
3332
if (0 === strpos($pathinfo, '/foo')) {
3433
// foo
3534
if (preg_match('#^/foo/(?P<bar>baz|symfony)$#s', $pathinfo, $matches)) {
@@ -83,24 +82,34 @@ public function match($rawPathinfo)
8382
// baz3
8483
if ('/test/baz3' === $trimmedPathinfo) {
8584
$ret = array('_route' => 'baz3');
86-
if (substr($pathinfo, -1) !== '/') {
85+
if ('/' === substr($pathinfo, -1)) {
86+
// no-op
87+
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
88+
goto not_baz3;
89+
} else {
8790
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'baz3'));
8891
}
8992

9093
return $ret;
9194
}
95+
not_baz3:
9296

9397
}
9498

9599
// baz4
96100
if (preg_match('#^/test/(?P<foo>[^/]++)/?$#s', $pathinfo, $matches)) {
97101
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ());
98-
if (substr($pathinfo, -1) !== '/') {
102+
if ('/' === substr($pathinfo, -1)) {
103+
// no-op
104+
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
105+
goto not_baz4;
106+
} else {
99107
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'baz4'));
100108
}
101109

102110
return $ret;
103111
}
112+
not_baz4:
104113

105114
// baz5
106115
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
@@ -179,12 +188,17 @@ public function match($rawPathinfo)
179188
// hey
180189
if ('/multi/hey' === $trimmedPathinfo) {
181190
$ret = array('_route' => 'hey');
182-
if (substr($pathinfo, -1) !== '/') {
191+
if ('/' === substr($pathinfo, -1)) {
192+
// no-op
193+
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
194+
goto not_hey;
195+
} else {
183196
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'hey'));
184197
}
185198

186199
return $ret;
187200
}
201+
not_hey:
188202

189203
// overridden2
190204
if ('/multi/new' === $pathinfo) {

Tests/Fixtures/dumper/url_matcher3.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ public function match($rawPathinfo)
2121
$pathinfo = rawurldecode($rawPathinfo);
2222
$trimmedPathinfo = rtrim($pathinfo, '/');
2323
$context = $this->context;
24-
$request = $this->request;
24+
$request = $this->request ?: $this->createRequest($pathinfo);
2525
$requestMethod = $canonicalMethod = $context->getMethod();
2626
$scheme = $context->getScheme();
2727

2828
if ('HEAD' === $requestMethod) {
2929
$canonicalMethod = 'GET';
3030
}
3131

32-
3332
if (0 === strpos($pathinfo, '/rootprefix')) {
3433
// static
3534
if ('/rootprefix/test' === $pathinfo) {

Tests/Fixtures/dumper/url_matcher4.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ public function match($rawPathinfo)
2121
$pathinfo = rawurldecode($rawPathinfo);
2222
$trimmedPathinfo = rtrim($pathinfo, '/');
2323
$context = $this->context;
24-
$request = $this->request;
24+
$request = $this->request ?: $this->createRequest($pathinfo);
2525
$requestMethod = $canonicalMethod = $context->getMethod();
2626
$scheme = $context->getScheme();
2727

2828
if ('HEAD' === $requestMethod) {
2929
$canonicalMethod = 'GET';
3030
}
3131

32-
3332
// just_head
3433
if ('/just_head' === $pathinfo) {
3534
if ('HEAD' !== $requestMethod) {

Tests/Fixtures/dumper/url_matcher5.php

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ public function match($rawPathinfo)
2121
$pathinfo = rawurldecode($rawPathinfo);
2222
$trimmedPathinfo = rtrim($pathinfo, '/');
2323
$context = $this->context;
24-
$request = $this->request;
24+
$request = $this->request ?: $this->createRequest($pathinfo);
2525
$requestMethod = $canonicalMethod = $context->getMethod();
2626
$scheme = $context->getScheme();
2727

2828
if ('HEAD' === $requestMethod) {
2929
$canonicalMethod = 'GET';
3030
}
3131

32-
3332
if (0 === strpos($pathinfo, '/a')) {
3433
// a_first
3534
if ('/a/11' === $pathinfo) {
@@ -57,32 +56,47 @@ public function match($rawPathinfo)
5756
// a_fourth
5857
if ('/a/44' === $trimmedPathinfo) {
5958
$ret = array('_route' => 'a_fourth');
60-
if (substr($pathinfo, -1) !== '/') {
59+
if ('/' === substr($pathinfo, -1)) {
60+
// no-op
61+
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
62+
goto not_a_fourth;
63+
} else {
6164
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'a_fourth'));
6265
}
6366

6467
return $ret;
6568
}
69+
not_a_fourth:
6670

6771
// a_fifth
6872
if ('/a/55' === $trimmedPathinfo) {
6973
$ret = array('_route' => 'a_fifth');
70-
if (substr($pathinfo, -1) !== '/') {
74+
if ('/' === substr($pathinfo, -1)) {
75+
// no-op
76+
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
77+
goto not_a_fifth;
78+
} else {
7179
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'a_fifth'));
7280
}
7381

7482
return $ret;
7583
}
84+
not_a_fifth:
7685

7786
// a_sixth
7887
if ('/a/66' === $trimmedPathinfo) {
7988
$ret = array('_route' => 'a_sixth');
80-
if (substr($pathinfo, -1) !== '/') {
89+
if ('/' === substr($pathinfo, -1)) {
90+
// no-op
91+
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
92+
goto not_a_sixth;
93+
} else {
8194
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'a_sixth'));
8295
}
8396

8497
return $ret;
8598
}
99+
not_a_sixth:
86100

87101
}
88102

@@ -95,65 +109,95 @@ public function match($rawPathinfo)
95109
// nested_a
96110
if ('/nested/group/a' === $trimmedPathinfo) {
97111
$ret = array('_route' => 'nested_a');
98-
if (substr($pathinfo, -1) !== '/') {
112+
if ('/' === substr($pathinfo, -1)) {
113+
// no-op
114+
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
115+
goto not_nested_a;
116+
} else {
99117
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'nested_a'));
100118
}
101119

102120
return $ret;
103121
}
122+
not_nested_a:
104123

105124
// nested_b
106125
if ('/nested/group/b' === $trimmedPathinfo) {
107126
$ret = array('_route' => 'nested_b');
108-
if (substr($pathinfo, -1) !== '/') {
127+
if ('/' === substr($pathinfo, -1)) {
128+
// no-op
129+
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
130+
goto not_nested_b;
131+
} else {
109132
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'nested_b'));
110133
}
111134

112135
return $ret;
113136
}
137+
not_nested_b:
114138

115139
// nested_c
116140
if ('/nested/group/c' === $trimmedPathinfo) {
117141
$ret = array('_route' => 'nested_c');
118-
if (substr($pathinfo, -1) !== '/') {
142+
if ('/' === substr($pathinfo, -1)) {
143+
// no-op
144+
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
145+
goto not_nested_c;
146+
} else {
119147
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'nested_c'));
120148
}
121149

122150
return $ret;
123151
}
152+
not_nested_c:
124153

125154
}
126155

127156
elseif (0 === strpos($pathinfo, '/slashed/group')) {
128157
// slashed_a
129158
if ('/slashed/group' === $trimmedPathinfo) {
130159
$ret = array('_route' => 'slashed_a');
131-
if (substr($pathinfo, -1) !== '/') {
160+
if ('/' === substr($pathinfo, -1)) {
161+
// no-op
162+
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
163+
goto not_slashed_a;
164+
} else {
132165
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'slashed_a'));
133166
}
134167

135168
return $ret;
136169
}
170+
not_slashed_a:
137171

138172
// slashed_b
139173
if ('/slashed/group/b' === $trimmedPathinfo) {
140174
$ret = array('_route' => 'slashed_b');
141-
if (substr($pathinfo, -1) !== '/') {
175+
if ('/' === substr($pathinfo, -1)) {
176+
// no-op
177+
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
178+
goto not_slashed_b;
179+
} else {
142180
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'slashed_b'));
143181
}
144182

145183
return $ret;
146184
}
185+
not_slashed_b:
147186

148187
// slashed_c
149188
if ('/slashed/group/c' === $trimmedPathinfo) {
150189
$ret = array('_route' => 'slashed_c');
151-
if (substr($pathinfo, -1) !== '/') {
190+
if ('/' === substr($pathinfo, -1)) {
191+
// no-op
192+
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
193+
goto not_slashed_c;
194+
} else {
152195
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'slashed_c'));
153196
}
154197

155198
return $ret;
156199
}
200+
not_slashed_c:
157201

158202
}
159203

Tests/Fixtures/dumper/url_matcher6.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ public function match($rawPathinfo)
2121
$pathinfo = rawurldecode($rawPathinfo);
2222
$trimmedPathinfo = rtrim($pathinfo, '/');
2323
$context = $this->context;
24-
$request = $this->request;
24+
$request = $this->request ?: $this->createRequest($pathinfo);
2525
$requestMethod = $canonicalMethod = $context->getMethod();
2626
$scheme = $context->getScheme();
2727

2828
if ('HEAD' === $requestMethod) {
2929
$canonicalMethod = 'GET';
3030
}
3131

32-
3332
if (0 === strpos($pathinfo, '/trailing/simple')) {
3433
// simple_trailing_slash_no_methods
3534
if ('/trailing/simple/no-methods/' === $pathinfo) {

0 commit comments

Comments
 (0)