Skip to content

Commit aed5991

Browse files
Merge branch '4.0'
* 4.0: [Routing] Throw 405 instead of 404 when redirect is not possible [Process] fix test case Add security.tl.xlf to legacy directory [Security][Validator] Add translations for Tagalog fixed typo Typo fix in security component lithuanian translation. [TwigBundle][WebProfilerBundle] Fix JS collision [Process] Check PHP_BINDIR before $PATH in PhpExecutableFinder
2 parents a2f7982 + f32a50d commit aed5991

File tree

14 files changed

+601
-139
lines changed

14 files changed

+601
-139
lines changed

src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
addEventListener: addEventListener,
3838
3939
createTabs: function() {
40-
var tabGroups = document.querySelectorAll('.sf-tabs');
40+
var tabGroups = document.querySelectorAll('.sf-tabs:not([data-processed=true])');
4141
4242
/* create the tab navigation for each group of tabs */
4343
for (var i = 0; i < tabGroups.length; i++) {
@@ -99,11 +99,13 @@
9999
document.getElementById(activeTabId).className = 'block';
100100
});
101101
}
102+
103+
tabGroups[i].setAttribute('data-processed', 'true');
102104
}
103105
},
104106
105107
createToggles: function() {
106-
var toggles = document.querySelectorAll('.sf-toggle');
108+
var toggles = document.querySelectorAll('.sf-toggle:not([data-processed=true])');
107109
108110
for (var i = 0; i < toggles.length; i++) {
109111
var elementSelector = toggles[i].getAttribute('data-toggle-selector');
@@ -156,14 +158,16 @@
156158
var altContent = toggle.getAttribute('data-toggle-alt-content');
157159
toggle.innerHTML = currentContent !== altContent ? altContent : originalContent;
158160
});
159-
}
160161
161-
/* Prevents from disallowing clicks on links inside toggles */
162-
var toggleLinks = document.querySelectorAll('.sf-toggle a');
163-
for (var i = 0; i < toggleLinks.length; i++) {
164-
addEventListener(toggleLinks[i], 'click', function(e) {
165-
e.stopPropagation();
166-
});
162+
/* Prevents from disallowing clicks on links inside toggles */
163+
var toggleLinks = toggles[i].querySelectorAll('a');
164+
for (var j = 0; j < toggleLinks.length; j++) {
165+
addEventListener(toggleLinks[j], 'click', function(e) {
166+
e.stopPropagation();
167+
});
168+
}
169+
170+
toggles[i].setAttribute('data-processed', 'true');
167171
}
168172
}
169173
};

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@
393393
},
394394
395395
createTabs: function() {
396-
var tabGroups = document.querySelectorAll('.sf-tabs');
396+
var tabGroups = document.querySelectorAll('.sf-tabs:not([data-processed=true])');
397397
398398
/* create the tab navigation for each group of tabs */
399399
for (var i = 0; i < tabGroups.length; i++) {
@@ -455,11 +455,13 @@
455455
document.getElementById(activeTabId).className = 'block';
456456
});
457457
}
458+
459+
tabGroups[i].setAttribute('data-processed', 'true');
458460
}
459461
},
460462
461463
createToggles: function() {
462-
var toggles = document.querySelectorAll('.sf-toggle');
464+
var toggles = document.querySelectorAll('.sf-toggle:not([data-processed=true])');
463465
464466
for (var i = 0; i < toggles.length; i++) {
465467
var elementSelector = toggles[i].getAttribute('data-toggle-selector');
@@ -512,14 +514,16 @@
512514
var altContent = toggle.getAttribute('data-toggle-alt-content');
513515
toggle.innerHTML = currentContent !== altContent ? altContent : originalContent;
514516
});
515-
}
516517
517-
/* Prevents from disallowing clicks on links inside toggles */
518-
var toggleLinks = document.querySelectorAll('.sf-toggle a');
519-
for (var i = 0; i < toggleLinks.length; i++) {
520-
addEventListener(toggleLinks[i], 'click', function(e) {
521-
e.stopPropagation();
522-
});
518+
/* Prevents from disallowing clicks on links inside toggles */
519+
var toggleLinks = toggles[i].querySelectorAll('a');
520+
for (var j = 0; j < toggleLinks.length; j++) {
521+
addEventListener(toggleLinks[j], 'click', function(e) {
522+
e.stopPropagation();
523+
});
524+
}
525+
526+
toggles[i].setAttribute('data-processed', 'true');
523527
}
524528
}
525529
};

src/Symfony/Component/Process/PhpExecutableFinder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public function find($includeArgs = true)
6565
}
6666
}
6767

68+
if (is_executable($php = PHP_BINDIR.('\\' === DIRECTORY_SEPARATOR ? '\\php.exe' : '/php'))) {
69+
return $php;
70+
}
71+
6872
$dirs = array(PHP_BINDIR);
6973
if ('\\' === DIRECTORY_SEPARATOR) {
7074
$dirs[] = 'C:\xampp\php\\';

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

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
237237
$hostMatches = false;
238238
$methods = $route->getMethods();
239239

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

243243
if (!count($compiledRoute->getPathVariables()) && false !== preg_match('#^(.)\^(?P<url>.*?)\$\1#'.('u' === substr($regex, -1) ? 'u' : ''), $regex, $m)) {
@@ -279,59 +279,6 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
279279

280280
$gotoname = 'not_'.preg_replace('/[^A-Za-z0-9_]/', '', $name);
281281

282-
if ($methods) {
283-
if (1 === count($methods)) {
284-
if ('HEAD' === $methods[0]) {
285-
$code .= <<<EOF
286-
if ('HEAD' !== \$requestMethod) {
287-
\$allow[] = 'HEAD';
288-
goto $gotoname;
289-
}
290-
291-
292-
EOF;
293-
} else {
294-
$code .= <<<EOF
295-
if ('$methods[0]' !== \$canonicalMethod) {
296-
\$allow[] = '$methods[0]';
297-
goto $gotoname;
298-
}
299-
300-
301-
EOF;
302-
}
303-
} else {
304-
$methodVariable = 'requestMethod';
305-
306-
if (in_array('GET', $methods)) {
307-
// Since we treat HEAD requests like GET requests we don't need to match it.
308-
$methodVariable = 'canonicalMethod';
309-
$methods = array_values(array_filter($methods, function ($method) { return 'HEAD' !== $method; }));
310-
}
311-
312-
if (1 === count($methods)) {
313-
$code .= <<<EOF
314-
if ('$methods[0]' !== \$$methodVariable) {
315-
\$allow[] = '$methods[0]';
316-
goto $gotoname;
317-
}
318-
319-
320-
EOF;
321-
} else {
322-
$methods = implode("', '", $methods);
323-
$code .= <<<EOF
324-
if (!in_array(\$$methodVariable, array('$methods'))) {
325-
\$allow = array_merge(\$allow, array('$methods'));
326-
goto $gotoname;
327-
}
328-
329-
330-
EOF;
331-
}
332-
}
333-
}
334-
335282
// the offset where the return value is appended below, with indendation
336283
$retOffset = 12 + strlen($code);
337284

@@ -362,6 +309,7 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
362309
if ('/' === substr(\$pathinfo, -1)) {
363310
// no-op
364311
} elseif ('GET' !== \$canonicalMethod) {
312+
\$allow[] = 'GET';
365313
goto $gotoname;
366314
} else {
367315
return array_replace(\$ret, \$this->redirect(\$rawPathinfo.'/', '$name'));
@@ -379,21 +327,79 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
379327
$code .= <<<EOF
380328
\$requiredSchemes = $schemes;
381329
if (!isset(\$requiredSchemes[\$context->getScheme()])) {
330+
if (!in_array(\$this->context->getMethod(), array('HEAD', 'GET'))) {
331+
\$allow[] = 'GET';
332+
goto $gotoname;
333+
}
334+
382335
return array_replace(\$ret, \$this->redirect(\$rawPathinfo, '$name', key(\$requiredSchemes)));
383336
}
384337
385338
386339
EOF;
387340
}
388341

389-
if ($hasTrailingSlash || $schemes) {
342+
if ($methods) {
343+
if (1 === count($methods)) {
344+
if ('HEAD' === $methods[0]) {
345+
$code .= <<<EOF
346+
if ('HEAD' !== \$requestMethod) {
347+
\$allow[] = 'HEAD';
348+
goto $gotoname;
349+
}
350+
351+
352+
EOF;
353+
} else {
354+
$code .= <<<EOF
355+
if ('$methods[0]' !== \$canonicalMethod) {
356+
\$allow[] = '$methods[0]';
357+
goto $gotoname;
358+
}
359+
360+
361+
EOF;
362+
}
363+
} else {
364+
$methodVariable = 'requestMethod';
365+
366+
if (in_array('GET', $methods)) {
367+
// Since we treat HEAD requests like GET requests we don't need to match it.
368+
$methodVariable = 'canonicalMethod';
369+
$methods = array_values(array_filter($methods, function ($method) { return 'HEAD' !== $method; }));
370+
}
371+
372+
if (1 === count($methods)) {
373+
$code .= <<<EOF
374+
if ('$methods[0]' !== \$$methodVariable) {
375+
\$allow[] = '$methods[0]';
376+
goto $gotoname;
377+
}
378+
379+
380+
EOF;
381+
} else {
382+
$methods = implode("', '", $methods);
383+
$code .= <<<EOF
384+
if (!in_array(\$$methodVariable, array('$methods'))) {
385+
\$allow = array_merge(\$allow, array('$methods'));
386+
goto $gotoname;
387+
}
388+
389+
390+
EOF;
391+
}
392+
}
393+
}
394+
395+
if ($hasTrailingSlash || $schemes || $methods) {
390396
$code .= " return \$ret;\n";
391397
} else {
392398
$code = substr_replace($code, 'return', $retOffset, 6);
393399
}
394400
$code .= " }\n";
395401

396-
if ($methods || $hasTrailingSlash) {
402+
if ($hasTrailingSlash || $schemes || $methods) {
397403
$code .= " $gotoname:\n";
398404
}
399405

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,25 @@ public function match($rawPathinfo)
4444
elseif (0 === strpos($pathinfo, '/bar')) {
4545
// bar
4646
if (preg_match('#^/bar/(?P<foo>[^/]++)$#sD', $pathinfo, $matches)) {
47+
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ());
4748
if ('GET' !== $canonicalMethod) {
4849
$allow[] = 'GET';
4950
goto not_bar;
5051
}
5152

52-
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ());
53+
return $ret;
5354
}
5455
not_bar:
5556

5657
// barhead
5758
if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]++)$#sD', $pathinfo, $matches)) {
59+
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ());
5860
if ('GET' !== $canonicalMethod) {
5961
$allow[] = 'GET';
6062
goto not_barhead;
6163
}
6264

63-
return $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ());
65+
return $ret;
6466
}
6567
not_barhead:
6668

@@ -92,23 +94,25 @@ public function match($rawPathinfo)
9294

9395
// baz5
9496
if (preg_match('#^/test/(?P<foo>[^/]++)/$#sD', $pathinfo, $matches)) {
97+
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ());
9598
if ('POST' !== $canonicalMethod) {
9699
$allow[] = 'POST';
97100
goto not_baz5;
98101
}
99102

100-
return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ());
103+
return $ret;
101104
}
102105
not_baz5:
103106

104107
// baz.baz6
105108
if (preg_match('#^/test/(?P<foo>[^/]++)/$#sD', $pathinfo, $matches)) {
109+
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ());
106110
if ('PUT' !== $canonicalMethod) {
107111
$allow[] = 'PUT';
108112
goto not_bazbaz6;
109113
}
110114

111-
return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ());
115+
return $ret;
112116
}
113117
not_bazbaz6:
114118

0 commit comments

Comments
 (0)