8000 merged branch Tobion/routing-pcre (PR #6064) · rvdbogerd/symfony@077bd35 · GitHub
[go: up one dir, main page]

Skip to content

Commit 077bd35

Browse files
committed
merged branch Tobion/routing-pcre (PR symfony#6064)
This PR was merged into the master branch. Commits ------- 824a0f3 [Routing] compatibility with older PCRE (pre 8) Discussion ---------- [Routing] compatibility with older PCRE (pre 8) symfony#6062 for master
2 parents cec11fa + 824a0f3 commit 077bd35

File tree

7 files changed

+66
-67
lines changed

7 files changed

+66
-67
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ private function regexToApacheRegex($regex)
215215
{
216216
$regexPatternEnd = strrpos($regex, $regex[0]);
217217

218-
return preg_replace('/\?<.+?>/', '', substr($regex, 1, $regexPatternEnd - 1));
218+
return preg_replace('/\?P<.+?>/', '', substr($regex, 1, $regexPatternEnd - 1));
219219
}
220220

221221
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
210210

211211
$supportsTrailingSlash = $supportsRedirections && (!$methods || in_array('HEAD', $methods));
212212

213-
if (!count($compiledRoute->getPathVariables()) && false !== preg_match('#^(.)\^(?<url>.*?)\$\1#', $compiledRoute->getRegex(), $m)) {
213+
if (!count($compiledRoute->getPathVariables()) && false !== preg_match('#^(.)\^(?P<url>.*?)\$\1#', $compiledRoute->getRegex(), $m)) {
214214
if ($supportsTrailingSlash && substr($m['url'], -1) === '/') {
215215
$conditions[] = sprintf("rtrim(\$pathinfo, '/') === %s", var_export(rtrim(str_replace('\\', '', $m['url']), '/'), true));
216216
$hasTrailingSlash = true;

src/Symfony/Component/Routing/RouteCompiler.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class RouteCompiler implements RouteCompilerInterface
3333
*
3434
* @throws \LogicException If a variable is referenced more than once
3535
* @throws \DomainException If a variable name is numeric because PHP raises an error for such
36-
* subpatterns in PCRE and thus would break matching, e.g. "(?<123>.+)".
36+
* subpatterns in PCRE and thus would break matching, e.g. "(?P<123>.+)".
3737
*/
3838
public function compile(Route $route)
3939
{
@@ -82,7 +82,6 @@ public function compile(Route $route)
8282

8383
private function compilePattern(Route $route, $pattern, $isHostname)
8484
{
85-
$len = strlen($pattern);
8685
$tokens = array();
8786
$variables = array();
8887
$matches = array();

src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php

Lines changed: 23 additions & 23 deletions
7802
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public function match($pathinfo)
2626
$pathinfo = rawurldecode($pathinfo);
2727

2828
// foo
29-
if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?<bar>baz|symfony)$#s', $pathinfo, $matches)) {
29+
if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?P<bar>baz|symfony)$#s', $pathinfo, $matches)) {
3030
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo')), array ( 'def' => 'test',));
3131
}
3232

3333
if (0 === strpos($pathinfo, '/bar')) {
3434
// bar
35-
if (preg_match('#^/bar/(?<foo>[^/]++)$#s', $pathinfo, $matches)) {
35+
if (preg_match('#^/bar/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
3636
if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) {
3737
$allow = array_merge($allow, array('GET', 'HEAD'));
3838
goto not_bar;
@@ -43,7 +43,7 @@ public function match($pathinfo)
4343
not_bar:
1E79 4444

4545
// barhead
46-
if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?<foo>[^/]++)$#s', $pathinfo, $matches)) {
46+
if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
4747
if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) {
4848
$allow = array_merge($allow, array('GET', 'HEAD'));
4949
goto not_barhead;
@@ -74,12 +74,12 @@ public function match($pathinfo)
7474
}
7575

7676
// baz4
77-
if (preg_match('#^/test/(?<foo>[^/]++)/$#s', $pathinfo, $matches)) {
77+
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
7878
return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ());
7979
}
8080

8181
// baz5
82-
if (preg_match('#^/test/(?<foo>[^/]++)/$#s', $pathinfo, $matches)) {
82+
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
8383
if ($this->context->getMethod() != 'POST') {
8484
$allow[] = 'POST';
8585
goto not_baz5;
@@ -90,7 +90,7 @@ public function match($pathinfo)
9090
not_baz5:
9191

9292
// baz.baz6
93-
if (preg_match('#^/test/(?<foo>[^/]++)/$#s', $pathinfo, $matches)) {
93+
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
9494
if ($this->context->getMethod() != 'PUT') {
9595
$allow[] = 'PUT';
9696
goto not_bazbaz6;
@@ -108,7 +108,7 @@ public function match($pathinfo)
108108
}
109109

110110
// quoter
111-
if (preg_match('#^/(?<quoter>[\']+)$#s', $pathinfo, $matches)) {
111+
if (preg_match('#^/(?P<quoter>[\']+)$#s', $pathinfo, $matches)) {
112112
return $this->mergeDefaults(array_replace($matches, array('_route' => 'quoter')), array ());
113113
}
114114

@@ -120,30 +120,30 @@ public function match($pathinfo)
120120
if (0 === strpos($pathinfo, '/a')) {
121121
if (0 === strpos($pathinfo, '/a/b\'b')) {
122122
// foo1
123-
if (preg_match('#^/a/b\'b/(?<foo>[^/]++)$#s', $pathinfo, $matches)) {
123+
if (preg_match('#^/a/b\'b/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
124124
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo1')), array ());
125125
}
126126

127127
// bar1
128-
if (preg_match('#^/a/b\'b/(?<bar>[^/]++)$#s', $pathinfo, $matches)) {
128+
if (preg_match('#^/a/b\'b/(?P<bar>[^/]++)$#s', $pathinfo, $matches)) {
129129
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar1')), array ());
130130
}
131131

132132
}
133133

134134
// overridden
135-
if (preg_match('#^/a/(?<var>.*)$#s', $pathinfo, $matches)) {
135+
if (preg_match('#^/a/(?P<var>.*)$#s', $pathinfo, $matches)) {
136136
return $this->mergeDefaults(array_replace($matches, array('_route' => 'overridden')), array ());
137137
}
138138

139139
if (0 === strpos($pathinfo, '/a/b\'b')) {
140140
// foo2
141-
if (preg_match('#^/a/b\'b/(?<foo1>[^/]++)$#s', $pathinfo, $matches)) {
141+
if (preg_match('#^/a/b\'b/(?P<foo1>[^/]++)$#s', $pathinfo, $matches)) {
142142
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo2')), array ());
143143
}
144144

145145
// bar2
146-
if (preg_match('#^/a/b\'b/(?<bar1>[^/]++)$#s', $pathinfo, $matches)) {
146+
if (preg_match('#^/a/b\'b/(?P<bar1>[^/]++)$#s', $pathinfo, $matches)) {
147147
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar2')), array ());
148148
}
149149

@@ -153,7 +153,7 @@ public function match($pathinfo)
153153

154154
if (0 === strpos($pathinfo, '/multi')) {
155155
// helloWorld
156-
if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?<who>[^/]++))?$#s', $pathinfo, $matches)) {
156+
if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?P<who>[^/]++))?$#s', $pathinfo, $matches)) {
157157
return $this->mergeDefaults(array_replace($matches, array('_route' => 'helloWorld')), array ( 'who' => 'World!',));
158158
}
159159

@@ -170,12 +170,12 @@ public function match($pathinfo)
170170
}
171171

172172
// foo3
173-
if (preg_match('#^/(?<_locale>[^/]++)/b/(?<foo>[^/]++)$#s', $pathinfo, $matches)) {
173+
if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
174174
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo3')), array ());
175175
}
176176

177177
// bar3
178-
if (preg_match('#^/(?<_locale>[^/]++)/b/(?<bar>[^/]++)$#s', $pathinfo, $matches)) {
178+
if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<bar>[^/]++)$#s', $pathinfo, $matches)) {
179179
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar3')), array ());
180180
}
181181

@@ -186,7 +186,7 @@ public function match($pathinfo)
186186
}
187187

188188
// foo4
189-
if (preg_match('#^/aba/(?<foo>[^/]++)$#s', $pathinfo, $matches)) {
189+
if (preg_match('#^/aba/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
190190
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo4')), array ());
191191
}
192192

@@ -236,7 +236,7 @@ public function match($pathinfo)
236236
return array('_route' => 'route6');
237237
}
238238

239-
if (preg_match('#^(?<var1>[^\\.]++)\\.example\\.com$#s', $hostname, $hostnameMatches)) {
239+
if (preg_match('#^(?P<var1>[^\\.]++)\\.example\\.com$#s', $hostname, $hostnameMatches)) {
240240
if (0 === strpos($pathinfo, '/route1')) {
241241
// route11
242242
if ($pathinfo === '/route11') {
@@ -249,12 +249,12 @@ public function match($pathinfo)
249249
}
250250

251251
// route13
252-
if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?<name>[^/]++)$#s', $pathinfo, $matches)) {
252+
if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
253253
return $this->mergeDefaults(array_replace($hostnameMatches, $matches, array('_route' => 'route13')), array ());
254254
}
255255

256256
// route14
257-
if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?<name>[^/]++)$#s', $pathinfo, $matches)) {
257+
if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
258258
return $this->mergeDefaults(array_replace($hostnameMatches, $matches, array('_route' => 'route14')), array ( 'var1' => 'val',));
259259
}
260260

@@ -264,15 +264,15 @@ public function match($pathinfo)
264264

265265
if (preg_match('#^c\\.example\\.com$#s', $hostname, $hostnameMatches)) {
266266
// route15
267-
if (0 === strpos($pathinfo, '/route15') && preg_match('#^/route15/(?<name>[^/]++)$#s', $pathinfo, $matches)) {
267+
if (0 === strpos($pathinfo, '/route15') && preg_match('#^/route15/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
268268
return $this->mergeDefaults(array_replace($matches, array('_route' => 'route15')), array ());
269269
}
270270

271271
}
272272

273273
if (0 === strpos($pathinfo, '/route1')) {
274274
// route16
275-
if (0 === strpos($pathinfo, '/route16') && preg_match('#^/route16/(?<name>[^/]++)$#s', $pathinfo, $matches)) {
275+
if (0 === strpos($pathinfo, '/route16') && preg_match('#^/route16/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
276276
return $this->mergeDefaults(array_replace($matches, array('_route' => 'route16')), array ( 'var1' => 'val',));
277277
}
278278

@@ -291,12 +291,12 @@ public function match($pathinfo)
291291

292292
if (0 === strpos($pathinfo, '/a/b')) {
293293
// b
294-
if (preg_match('#^/a/b/(?<var>[^/]++)$#s', $pathinfo, $matches)) {
294+
if (preg_match('#^/a/b/(?P<var>[^/]++)$#s', $pathinfo, $matches)) {
295295
return $this->mergeDefaults(array_replace($matches, array('_route' => 'b')), array ());
296296
}
297297

298298
// c
299-
if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?<var>[^/]++)$#s', $pathinfo, $matches)) {
299+
if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?P<var>[^/]++)$#s', $pathinfo, $matches)) {
300300
return $this->mergeDefaults(array_replace($matches, array('_route' => 'c')), array ());
301301
}
302302

0 commit comments

Comments
 (0)
0