8000 merged branch Tobion/routing-centos (PR #6062) · symfony/symfony@8f33f2e · GitHub
[go: up one dir, main page]

Skip to content

Commit 8f33f2e

Browse files
committed
merged branch Tobion/routing-centos (PR #6062)
This PR was merged into the 2.1 branch. Commits ------- 1daefa5 [Routing] made it compatible with older PCRE version (pre 8) Discussion ---------- [Routing] compatibility with older PCRE version (pre 8) fixes #4093 Ok I changed my mind about this issue. 1. I figured more people are affected than I thought and CentOS is stubborn. 2. Symfony still uses the old regex style `?P<param>` in several other components. So also doing so in the routing makes it more consistent. 3. Even if it's definitely not good to use an over 6 year old PCRE version with a recent PHP version, we can still try to provide the best experience. It doesn't mean we support outdated software stacks of custom PHP compilations as we won't and cannot specifically test against it. @fabpot: I will do a seperate PR on master when you merged this because the code changed alot in master so it cannot easily be merged I guess. I will also convert the symfony requirement for PCRE in the requirements check to a recommendation.
2 parents c4631c5 + 1daefa5 commit 8f33f2e

File tree

7 files changed

+51
-51
lines changed

7 files changed

+51
-51
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function dump(array $options = array())
5555
if (strlen($regex) < 2 || 0 === $regexPatternEnd) {
5656
throw new \LogicException('The "%s" route regex "%s" is invalid', $name, $regex);
5757
}
58-
$regex = preg_replace('/\?<.+?>/', '', substr($regex, 1, $regexPatternEnd - 1));
58+
$regex = preg_replace('/\?P<.+?>/', '', substr($regex, 1, $regexPatternEnd - 1));
5959
$regex = '^'.self::escape(preg_quote($options['base_uri']).substr($regex, 1), ' ', '\\');
6060

6161
$methods = array();

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

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

192192
$supportsTrailingSlash = $supportsRedirections && (!$methods || in_array('HEAD', $methods));
193193

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

src/Symfony/Component/Routing/RouteCompiler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ private function computeRegexp(array $tokens, $index, $firstOptional)
111111
// Variable tokens
112112
if (0 === $index && 0 === $firstOptional) {
113113
// When the only token is an optional variable token, the separator is required
114-
return sprintf('%s(?<%s>%s)?', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
114+
return sprintf('%s(?P<%s>%s)?', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
115115
} else {
116-
$regexp = sprintf('%s(?<%s>%s)', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
116+
$regexp = sprintf('%s(?P<%s>%s)', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
117117
if ($index >= $firstOptional) {
118118
// Enclose each optional token in a subpattern to make it optional.
119119
// "?:" means it is non-capturing, i.e. the portion of the subject string that

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ 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 array_merge($this->mergeDefaults($matches, array ( 'def' => 'test',)), array('_route' => 'foo'));
3131
}
3232

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

4646
// barhead
47-
if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?<foo>[^/]+)$#s', $pathinfo, $matches)) {
47+
if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]+)$#s', $pathinfo, $matches)) {
4848
if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) {
4949
$allow = array_merge($allow, array('GET', 'HEAD'));
5050
goto not_barhead;
@@ -72,14 +72,14 @@ public function match($pathinfo)
7272
}
7373

7474
// baz4
75-
if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?<foo>[^/]+)/$#s', $pathinfo, $matches)) {
75+
if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P<foo>[^/]+)/$#s', $pathinfo, $matches)) {
7676
$matches['_route'] = 'baz4';
7777

7878
return $matches;
7979
}
8080

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

9494
// baz.baz6
95-
if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?<foo>[^/]+)/$#s', $pathinfo, $matches)) {
95+
if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P<foo>[^/]+)/$#s', $pathinfo, $matches)) {
9696
if ($this->context->getMethod() != 'PUT') {
9797
$allow[] = 'PUT';
9898
goto not_bazbaz6;
@@ -110,7 +110,7 @@ public function match($pathinfo)
110110
}
111111

112112
// quoter
113-
if (preg_match('#^/(?<quoter>[\']+)$#s', $pathinfo, $matches)) {
113+
if (preg_match('#^/(?P<quoter>[\']+)$#s', $pathinfo, $matches)) {
114114
$matches['_route'] = 'quoter';
115115

116116
return $matches;
@@ -124,14 +124,14 @@ public function match($pathinfo)
124124
if (0 === strpos($pathinfo, '/a')) {
125125
if (0 === strpos($pathinfo, '/a/b\'b')) {
126126
// foo1
127-
if (preg_match('#^/a/b\'b/(?<foo>[^/]+)$#s', $pathinfo, $matches)) {
127+
if (preg_match('#^/a/b\'b/(?P<foo>[^/]+)$#s', $pathinfo, $matches)) {
128128
$matches['_route'] = 'foo1';
129129

130130
return $matches;
131131
}
132132

133133
// bar1
134-
if (preg_match('#^/a/b\'b/(?<bar>[^/]+)$#s', $pathinfo, $matches)) {
134+
if (preg_match('#^/a/b\'b/(?P<bar>[^/]+)$#s', $pathinfo, $matches)) {
135135
$matches['_route'] = 'bar1';
136136

137137
return $matches;
@@ -140,22 +140,22 @@ public function match($pathinfo)
140140
}
141141

142142
// overridden
143-
if (preg_match('#^/a/(?<var>.*)$#s', $pathinfo, $matches)) {
143+
if (preg_match('#^/a/(?P<var>.*)$#s', $pathinfo, $matches)) {
144144
$matches['_route'] = 'overridden';
145145

146146
return $matches;
147147
}
148148

149149
if (0 === strpos($pathinfo, '/a/b\'b')) {
150150
// foo2
151-
if (preg_match('#^/a/b\'b/(?<foo1>[^/]+)$#s', $pathinfo, $matches)) {
151+
if (preg_match('#^/a/b\'b/(?P<foo1>[^/]+)$#s', $pathinfo, $matches)) {
152152
$matches['_route'] = 'foo2';
153153

154154
return $matches;
155155
}
156156

157157
// bar2
158-
if (preg_match('#^/a/b\'b/(?<bar1>[^/]+)$#s', $pathinfo, $matches)) {
158+
if (preg_match('#^/a/b\'b/(?P<bar1>[^/]+)$#s', $pathinfo, $matches)) {
159159
$matches['_route'] = 'bar2';
160160

161161
return $matches;
@@ -167,7 +167,7 @@ public function match($pathinfo)
167167

168168
if (0 === strpos($pathinfo, '/multi')) {
169169
// helloWorld
170-
if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?<who>[^/]+))?$#s', $pathinfo, $matches)) {
170+
if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?P<who>[^/]+))?$#s', $pathinfo, $matches)) {
171171
return array_merge($this->mergeDefaults($matches, array ( 'who' => 'World!',)), array('_route' => 'helloWorld'));
172172
}
173173

@@ -184,14 +184,14 @@ public function match($pathinfo)
184184
}
185185

186186
// foo3
187-
if (preg_match('#^/(?<_locale>[^/]+)/b/(?<foo>[^/]+)$#s', $pathinfo, $matches)) {
187+
if (preg_match('#^/(?P<_locale>[^/]+)/b/(?P<foo>[^/]+)$#s', $pathinfo, $matches)) {
188188
$matches['_route'] = 'foo3';
189189

190190
return $matches;
191191
}
192192

193193
// bar3
194-
if (preg_match('#^/(?<_locale>[^/]+)/b/(?<bar>[^/]+)$#s', $pathinfo, $matches)) {
194+
if (preg_match('#^/(?P<_locale>[^/]+)/b/(?P<bar>[^/]+)$#s', $pathinfo, $matches)) {
195195
$matches['_route'] = 'bar3';
196196

197197
return $matches;
@@ -203,7 +203,7 @@ public function match($pathinfo)
203203
}
204204

205205
// foo4
206-
if (0 === strpos($pathinfo, '/aba') && preg_match('#^/aba/(?<foo>[^/]+)$#s', $pathinfo, $matches)) {
206+
if (0 === strpos($pathinfo, '/aba') && preg_match('#^/aba/(?P<foo>[^/]+)$#s', $pathinfo, $matches)) {
207207
$matches['_route'] = 'foo4';
208208

209209
return $matches;
@@ -217,14 +217,14 @@ public function match($pathinfo)
217217

218218
if (0 === strpos($pathinfo, '/a/b')) {
219219
// b
220-
if (preg_match('#^/a/b/(?<var>[^/]+)$#s', $pathinfo, $matches)) {
220+
if (preg_match('#^/a/b/(?P<var>[^/]+)$#s', $pathinfo, $matches)) {
221221
$matches['_route'] = 'b';
222222

223223
return $matches;
224224
}
225225

226226
// c
227-
if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?<var>[^/]+)$#s', $pathinfo, $matches)) {
227+
if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?P<var>[^/]+)$#s', $pathinfo, $matches)) {
228228
$matches['_route'] = 'c';
229229

230230
return $matches;

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ 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 array_merge($this->mergeDefaults($matches, array ( 'def' => 'test',)), array('_route' => 'foo'));
3131
}
3232

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

4646
// barhead
47-
if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?<foo>[^/]+)$#s', $pathinfo, $matches)) {
47+
if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]+)$#s', $pathinfo, $matches)) {
4848
if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) {
4949
$allow = array_merge($allow, array('GET', 'HEAD'));
5050
goto not_barhead;
@@ -76,7 +76,7 @@ public function match($pathinfo)
7676
}
7777

7878
// baz4
79-
if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?<foo>[^/]+)/?$#s', $pathinfo, $matches)) {
79+
if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P<foo>[^/]+)/?$#s', $pathinfo, $matches)) {
8080
if (substr($pathinfo, -1) !== '/') {
8181
return $this->redirect($pathinfo.'/', 'baz4');
8282
}
@@ -87,7 +87,7 @@ public function match($pathinfo)
8787
}
8888

8989
// baz5
90-
if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?<foo>[^/]+)/$#s', $pathinfo, $matches)) {
90+
if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P<foo>[^/]+)/$#s', $pathinfo, $matches)) {
9191
if ($this->context->getMethod() != 'POST') {
9292
$allow[] = 'POST';
9393
goto not_baz5;
@@ -100,7 +100,7 @@ public function match($pathinfo)
100100
not_baz5:
101101

102102
// baz.baz6
103-
if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?<foo>[^/]+)/$#s', $pathinfo, $matches)) {
103+
if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P<foo>[^/]+)/$#s', $pathinfo, $matches)) {
104104
if ($this->context->getMethod() != 'PUT') {
105105
$allow[] = 'PUT';
106106
goto not_bazbaz6;
@@ -118,7 +118,7 @@ public function match($pathinfo)
118118
}
119119

120120
// quoter
121-
if (preg_match('#^/(?<quoter>[\']+)$#s', $pathinfo, $matches)) {
121+
if (preg_match('#^/(?P<quoter>[\']+)$#s', $pathinfo, $matches)) {
122122
$matches['_route'] = 'quoter';
123123

124124
return $matches;
@@ -132,14 +132,14 @@ public function match($pathinfo)
132132
if (0 === strpos($pathinfo, '/a')) {
133133
if (0 === strpos($pathinfo, '/a/b\'b')) {
134134
// foo1
135-
if (preg_match('#^/a/b\'b/(?<foo>[^/]+)$#s', $pathinfo, $matches)) {
135+
if (preg_match('#^/a/b\'b/(?P<foo>[^/]+)$#s', $pathinfo, $matches)) {
136136
$matches['_route'] = 'foo1';
137137

138138
return $matches;
139139
}
140140

141141
// bar1
142-
if (preg_match('#^/a/b\'b/(?<bar>[^/]+)$#s', $pathinfo, $matches)) {
142+
if (preg_match('#^/a/b\'b/(?P<bar>[^/]+)$#s', $pathinfo, $matches)) {
143143
$matches['_route'] = 'bar1';
144144

145145
return $matches;
@@ -148,22 +148,22 @@ public function match($pathinfo)
148148
}
149149

150150
// overridden
151-
if (preg_match('#^/a/(?<var>.*)$#s', $pathinfo, $matches)) {
151+
if (preg_match('#^/a/(?P<var>.*)$#s', $pathinfo, $matches)) {
152152
$matches['_route'] = 'overridden';
153153

154154
return $matches;
155155
}
156156

157157
if (0 === strpos($pathinfo, '/a/b\'b')) {
158158
// foo2
159-
if (preg_match('#^/a/b\'b/(?<foo1>[^/]+)$#s', $pathinfo, $matches)) {
159+
if (preg_match('#^/a/b\'b/(?P<foo1>[^/]+)$#s', $pathinfo, $matches)) {
160160
$matches['_route'] = 'foo2';
161161

162162
return $matches;
163163
}
164164

165165
// bar2
166-
if (preg_match('#^/a/b\'b/(?<bar1>[^/]+)$#s', $pathinfo, $matches)) {
166+
if (preg_match('#^/a/b\'b/(?P<bar1>[^/]+)$#s', $pathinfo, $matches)) {
167167
$matches['_route'] = 'bar2';
168168

169169
return $matches;
@@ -175,7 +175,7 @@ public function match($pathinfo)
175175

176176
if (0 === strpos($pathinfo, '/multi')) {
177177
// helloWorld
178-
if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?<who>[^/]+))?$#s', $pathinfo, $matches)) {
178+
if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?P<who>[^/]+))?$#s', < F438 span class="pl-s1">$pathinfo, $matches)) {
179179
return array_merge($this->mergeDefaults($matches, array ( 'who' => 'World!',)), array('_route' => 'helloWorld'));
180180
}
181181

@@ -196,14 +196,14 @@ public function match($pathinfo)
196196
}
197197

198198
// foo3
199-
if (preg_match('#^/(?<_locale>[^/]+)/b/(?<foo>[^/]+)$#s', $pathinfo, $matches)) {
199+
if (preg_match('#^/(?P<_locale>[^/]+)/b/(?P<foo>[^/]+)$#s', $pathinfo, $matches)) {
200200
$matches['_route'] = 'foo3';
201201

202202
return $matches;
203203
}
204204

205205
// bar3
206-
if (preg_match('#^/(?<_locale>[^/]+)/b/(?<bar>[^/]+)$#s', $pathinfo, $matches)) {
206+
if (preg_match('#^/(?P<_locale>[^/]+)/b/(?P<bar>[^/]+)$#s', $pathinfo, $matches)) {
207207
$matches['_route'] = 'bar3';
208208

209209
return $matches;
@@ -215,7 +215,7 @@ public function match($pathinfo)
215215
}
216216

217217
// foo4
218-
if (0 === strpos($pathinfo, '/aba') && preg_match('#^/aba/(?<foo>[^/]+)$#s', $pathinfo, $matches)) {
218+
if (0 === strpos($pathinfo, '/aba') && preg_match('#^/aba/(?P<foo>[^/]+)$#s', $pathinfo, $matches)) {
219219
$matches['_route'] = 'foo4';
220220

221221
return $matches;
@@ -229,14 +229,14 @@ public function match($pathinfo)
229229

230230
if (0 === strpos($pathinfo, '/a/b')) {
231231
// b
232-
if (preg_match('#^/a/b/(?<var>[^/]+)$#s', $pathinfo, $matches)) {
232+
if (preg_match('#^/a/b/(?P<var>[^/]+)$#s', $pathinfo, $matches)) {
233233
$matches['_route'] = 'b';
234234

235235
return $matches;
236236
}
237237

238238
// c
239-
if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?<var>[^/]+)$#s', $pathinfo, $matches)) {
239+
if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?P<var> 975D [^/]+)$#s', $pathinfo, $matches)) {
240240
$matches['_route'] = 'c';
241241

242242
return $matches;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function match($pathinfo)
3232
}
3333

3434
// dynamic
35-
if (preg_match('#^/rootprefix/(?<var>[^/]+)$#s', $pathinfo, $matches)) {
35+
if (preg_match('#^/rootprefix/(?P<var>[^/]+)$#s', $pathinfo, $matches)) {
3636
$matches['_route'] = 'dynamic';
3737

3838
return $matches;

0 commit comments

Comments
 (0)
0