Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 71d4e36

Browse files
committed
[Routing] Allow GET requests to be redirected. Fixes #23004
1 parent 7a9875c commit 71d4e36

File tree

4 files changed

+454
-1
lines changed

4 files changed

+454
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
238238
$hostMatches = false;
239239
$methods = $route->getMethods();
240240

241-
$supportsTrailingSlash = $supportsRedirections && (!$methods || in_array('HEAD', $methods));
241+
$supportsTrailingSlash = $supportsRedirections && (!$methods || in_array('HEAD', $methods) || in_array('GET', $methods));
242242
$regex = $compiledRoute->getRegex();
243243

244244
if (!count($compiledRoute->getPathVariables()) && false !== preg_match('#^(.)\^(?P<url>.*?)\$\1#'.(substr($regex, -1) === 'u' ? 'u' : ''), $regex, $m)) {
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
<?php
2+
3+
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
4+
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
5+
use Symfony\Component\Routing\RequestContext;
6+
7+
/**
8+
* ProjectUrlMatcher.
9+
*
10+
* This class has been auto-generated
11+
* by the Symfony Routing Component.
12+
*/
13+
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
14+
{
15+
/**
16+
* Constructor.
17+
*/
18+
public function __construct(RequestContext $context)
19+
{
20+
$this->context = $context;
21+
}
22+
23+
public function match($pathinfo)
24+
{
25+
$allow = array();
26+
$pathinfo = rawurldecode($pathinfo);
27+
$trimmedPathinfo = rtrim($pathinfo, '/');
28+
$context = $this->context;
29+
$request = $this->request;
30+
$requestMethod = $canonicalMethod = $context->getMethod();
31+
$scheme = $context->getScheme();
32+
33+
if ('HEAD' === $requestMethod) {
34+
$canonicalMethod = 'GET';
35+
}
36+
37+
38+
if (0 === strpos($pathinfo, '/trailing/simple')) {
39+
// simple_trailing_slash_no_methods
40+
if ('/trailing/simple/no-methods/' === $pathinfo) {
41+
return array('_route' => 'simple_trailing_slash_no_methods');
42+
}
43+
44+
// simple_trailing_slash_GET_method
45+
if ('/trailing/simple/get-method/' === $pathinfo) {
46+
if ('GET' !== $canonicalMethod) {
47+
$allow[] = 'GET';
48+
goto not_simple_trailing_slash_GET_method;
49+
}
50+
51+
return array('_route' => 'simple_trailing_slash_GET_method');
52+
}
53+
not_simple_trailing_slash_GET_method:
54+
55+
// simple_trailing_slash_HEAD_method
56+
if ('/trailing/simple/head-method/' === $pathinfo) {
57+
if ('HEAD' !== $requestMethod) {
58+
$allow[] = 'HEAD';
59+
goto not_simple_trailing_slash_HEAD_method;
60+
}
61+
62+
return array('_route' => 'simple_trailing_slash_HEAD_method');
63+
}
64+
not_simple_trailing_slash_HEAD_method:
65+
66+
// simple_trailing_slash_POST_method
67+
if ('/trailing/simple/post-method/' === $pathinfo) {
68+
if ('POST' !== $canonicalMethod) {
69+
$allow[] = 'POST';
70+
goto not_simple_trailing_slash_POST_method;
71+
}
72+
73+
return array('_route' => 'simple_trailing_slash_POST_method');
74+
}
75+
not_simple_trailing_slash_POST_method:
76+
77+
}
78+
79+
elseif (0 === strpos($pathinfo, '/trailing/regex')) {
80+
// regex_trailing_slash_no_methods
81+
if (0 === strpos($pathinfo, '/trailing/regex/no-methods') && preg_match('#^/trailing/regex/no\\-methods/(?P<param>[^/]++)/$#s', $pathinfo, $matches)) {
82+
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_no_methods')), array ());
83+
}
84+
85+
// regex_trailing_slash_GET_method
86+
if (0 === strpos($pathinfo, '/trailing/regex/get-method') && preg_match('#^/trailing/regex/get\\-method/(?P<param>[^/]++)/$#s', $pathinfo, $matches)) {
87+
if ('GET' !== $canonicalMethod) {
88+
$allow[] = 'GET';
89+
goto not_regex_trailing_slash_GET_method;
90+
}
91+
92+
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_GET_method')), array ());
93+
}
94+
not_regex_trailing_slash_GET_method:
95+
96+
// regex_trailing_slash_HEAD_method
97+
if (0 === strpos($pathinfo, '/trailing/regex/head-method') && preg_match('#^/trailing/regex/head\\-method/(?P<param>[^/]++)/$#s', $pathinfo, $matches)) {
98+
if ('HEAD' !== $requestMethod) {
99+
$allow[] = 'HEAD';
100+
goto not_regex_trailing_slash_HEAD_method;
101+
}
102+
103+
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_HEAD_method')), array ());
104+
}
105+
not_regex_trailing_slash_HEAD_method:
106+
107+
// regex_trailing_slash_POST_method
108+
if (0 === strpos($pathinfo, '/trailing/regex/post-method') && preg_match('#^/trailing/regex/post\\-method/(?P<param>[^/]++)/$#s', $pathinfo, $matches)) {
109+
if ('POST' !== $canonicalMethod) {
110+
$allow[] = 'POST';
111+
goto not_regex_trailing_slash_POST_method;
112+
}
113+
114+
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_POST_method')), array ());
115+
}
116+
not_regex_trailing_slash_POST_method:
117+
118+
}
119+
120+
elseif (0 === strpos($pathinfo, '/not-trailing/simple')) {
121+
// simple_not_trailing_slash_no_methods
122+
if ('/not-trailing/simple/no-methods' === $pathinfo) {
123+
return array('_route' => 'simple_not_trailing_slash_no_methods');
124+
}
125+
126+
// simple_not_trailing_slash_GET_method
127+
if ('/not-trailing/simple/get-method' === $pathinfo) {
128+
if ('GET' !== $canonicalMethod) {
129+
$allow[] = 'GET';
130+
goto not_simple_not_trailing_slash_GET_method;
131+
}
132+
133+
return array('_route' => 'simple_not_trailing_slash_GET_method');
134+
}
135+
not_simple_not_trailing_slash_GET_method:
136+
137+
// simple_not_trailing_slash_HEAD_method
138+
if ('/not-trailing/simple/head-method' === $pathinfo) {
139+
if ('HEAD' !== $requestMethod) {
140+
$allow[] = 'HEAD';
141+
goto not_simple_not_trailing_slash_HEAD_method;
142+
}
143+
144+
return array('_route' => 'simple_not_trailing_slash_HEAD_method');
145+
}
146+
not_simple_not_trailing_slash_HEAD_method:
147+
148+
// simple_not_trailing_slash_POST_method
149+
if ('/not-trailing/simple/post-method' === $pathinfo) {
150+
if ('POST' !== $canonicalMethod) {
151+
$allow[] = 'POST';
152+
goto not_simple_not_trailing_slash_POST_method;
153+
}
154+
155+
return array('_route' => 'simple_not_trailing_slash_POST_method');
156+
}
157+
not_simple_not_trailing_slash_POST_method:
158+
159+
}
160+
161+
elseif (0 === strpos($pathinfo, '/not-trailing/regex')) {
162+
// regex_not_trailing_slash_no_methods
163+
if (0 === strpos($pathinfo, '/not-trailing/regex/no-methods') && preg_match('#^/not\\-trailing/regex/no\\-methods/(?P<param>[^/]++)$#s', $pathinfo, $matches)) {
164+
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_no_methods')), array ());
165+
}
166+
167+
// regex_not_trailing_slash_GET_method
168+
if (0 === strpos($pathinfo, '/not-trailing/regex/get-method') && preg_match('#^/not\\-trailing/regex/get\\-method/(?P<param>[^/]++)$#s', $pathinfo, $matches)) {
169+
if ('GET' !== $canonicalMethod) {
170+
$allow[] = 'GET';
171+
goto not_regex_not_trailing_slash_GET_method;
172+
}
173+
174+
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_GET_method')), array ());
175+
}
176+
not_regex_not_trailing_slash_GET_method:
177+
178+
// regex_not_trailing_slash_HEAD_method
179+
if (0 === strpos($pathinfo, '/not-trailing/regex/head-method') && preg_match('#^/not\\-trailing/regex/head\\-method/(?P<param>[^/]++)$#s', $pathinfo, $matches)) {
180+
if ('HEAD' !== $requestMethod) {
181+
$allow[] = 'HEAD';
182+
goto not_regex_not_trailing_slash_HEAD_method;
183+
}
184+
185+
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_HEAD_method')), array ());
186+
}
187+
not_regex_not_trailing_slash_HEAD_method:
188+
189+
// regex_not_trailing_slash_POST_method
190+
if (0 === strpos($pathinfo, '/not-trailing/regex/post-method') && preg_match('#^/not\\-trailing/regex/post\\-method/(?P<param>[^/]++)$#s', $pathinfo, $matches)) {
191+
if ('POST' !== $canonicalMethod) {
192+
$allow[] = 'POST';
193+
goto not_regex_not_trailing_slash_POST_method;
194+
}
195+
196+
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_POST_method')), array ());
197+
}
198+
not_regex_not_trailing_slash_POST_method:
199+
200+
}
201+
202+
throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
203+
}
204+
}

0 commit comments

Comments
 (0)