Skip to content

Commit 9e73cc7

Browse files
Merge branch '4.0'
* 4.0: [appveyor] set memory_limit=-1 [Console] Keep the modified exception handler [Console] Fix restoring exception handler [Router] Skip anonymous classes when loading annotated routes allow dashes in cwd pathname when running the tests Fixed Request::__toString ignoring cookies Make sure we only build once and have one time the prefix when importing routes [Security] Fix fatal error on non string username [FrameworkBundle] Automatically enable the CSRF if component *+ session* are loaded
2 parents d81f43f + e6157aa commit 9e73cc7

File tree

16 files changed

+175
-34
lines changed

16 files changed

+175
-34
lines changed

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ install:
2222
- 7z x php_apcu-5.1.8-7.1-ts-vc14-x86.zip -y >nul
2323
- cd ..
2424
- copy /Y php.ini-development php.ini-min
25+
- echo memory_limit=-1 >> php.ini-min
2526
- echo serialize_precision=14 >> php.ini-min
2627
- echo max_execution_time=1200 >> php.ini-min
2728
- echo date.timezone="America/Los_Angeles" >> php.ini-min

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\Form\Form;
2222
use Symfony\Component\Lock\Lock;
2323
use Symfony\Component\Lock\Store\SemaphoreStore;
24+
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
2425
use Symfony\Component\Serializer\Serializer;
2526
use Symfony\Component\Translation\Translator;
2627
use Symfony\Component\Validator\Validation;
@@ -109,7 +110,14 @@ private function addCsrfSection(ArrayNodeDefinition $rootNode)
109110
$rootNode
110111
->children()
111112
->arrayNode('csrf_protection')
112-
->canBeEnabled()
113+
->treatFalseLike(array('enabled' => false))
114+
->treatTrueLike(array('enabled' => true))
115+
->treatNullLike(array('enabled' => true))
116+
->addDefaultsIfNotSet()
117+
->children()
118+
// defaults to framework.session.enabled && !class_exists(FullStack::class) && interface_exists(CsrfTokenManagerInterface::class)
119+
->booleanNode('enabled')->defaultNull()->end()
120+
->end()
113121
->end()
114122
->end()
115123
;

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1818
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
1919
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
20+
use Symfony\Bundle\FullStack;
2021
use Symfony\Component\Cache\Adapter\AbstractAdapter;
2122
use Symfony\Component\Cache\Adapter\AdapterInterface;
2223
use Symfony\Component\Cache\Adapter\ArrayAdapter;
@@ -65,6 +66,7 @@
6566
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
6667
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
6768
use Symfony\Component\Security\Core\Security;
69+
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
6870
use Symfony\Component\Serializer\Encoder\DecoderInterface;
6971
use Symfony\Component\Serializer\Encoder\EncoderInterface;
7072
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata;
@@ -193,6 +195,11 @@ public function load(array $configs, ContainerBuilder $container)
193195
$this->registerRequestConfiguration($config['request'], $container, $loader);
194196
}
195197

198+
if (null === $config['csrf_protection']['enabled']) {
199+
$config['csrf_protection']['enabled'] = $this->sessionConfigEnabled && !class_exists(FullStack::class) && interface_exists(CsrfTokenManagerInterface::class);
200+
}
201+
$this->registerSecurityCsrfConfiguration($config['csrf_protection'], $container, $loader);
202+
196203
if ($this->isConfigEnabled($container, $config['form'])) {
197204
if (!class_exists('Symfony\Component\Form\Form')) {
198205
throw new LogicException('Form support cannot be enabled as the Form component is not installed.');
@@ -213,8 +220,6 @@ public function load(array $configs, ContainerBuilder $container)
213220
$container->removeDefinition('console.command.form_debug');
214221
}
215222

216-
$this->registerSecurityCsrfConfiguration($config['csrf_protection'], $container, $loader);
217-
218223
if ($this->isConfigEnabled($container, $config['assets'])) {
219224
if (!class_exists('Symfony\Component\Asset\Package')) {
220225
throw new LogicException('Asset support cannot be enabled as the Asset component is not installed.');

src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function testLoadFile()
5555
XmlUtils::loadFile($fixtures.'valid.xml', array($mock, 'validate'));
5656
$this->fail();
5757
} catch (\InvalidArgumentException $e) {
58-
$this->assertRegExp('/The XML file "[\w:\/\\\.]+" is not valid\./', $e->getMessage());
58+
$this->assertRegExp('/The XML file "[\w:\/\\\.-]+" is not valid\./', $e->getMessage());
5959
}
6060

6161
$this->assertInstanceOf('DOMDocument', XmlUtils::loadFile($fixtures.'valid.xml', array($mock, 'validate')));

src/Symfony/Component/Console/Application.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,18 @@ public function run(InputInterface $input = null, OutputInterface $output = null
158158
$exitCode = 1;
159159
}
160160
} finally {
161+
// if the exception handler changed, keep it
162+
// otherwise, unregister $renderException
161163
if (!$phpHandler) {
164+
if (set_exception_handler($renderException) === $renderException) {
165+
restore_exception_handler();
166+
}
162167
restore_exception_handler();
163168
} elseif (!$debugHandler) {
164-
$phpHandler[0]->setExceptionHandler(null);
169+
$finalHandler = $phpHandler[0]->setExceptionHandler(null);
170+
if ($finalHandler !== $renderException) {
171+
$phpHandler[0]->setExceptionHandler($finalHandler);
172+
}
165173
}
166174
}
167175

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,21 @@ public function __toString()
498498
return trigger_error($e, E_USER_ERROR);
499499
}
500500

501+
$cookieHeader = '';
502+
$cookies = array();
503+
504+
foreach ($this->cookies as $k => $v) {
505+
$cookies[] = $k.'='.$v;
506+
}
507+
508+
if (!empty($cookies)) {
509+
$cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n";
510+
}
511+
501512
return
502513
sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n".
503-
$this->headers."\r\n".
514+
$this->headers.
515+
$cookieHeader."\r\n".
504516
$content;
505517
}
506518

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1507,8 +1507,18 @@ public function testToString()
15071507
$request = new Request();
15081508

15091509
$request->headers->set('Accept-language', 'zh, en-us; q=0.8, en; q=0.6');
1510+
$request->cookies->set('Foo', 'Bar');
15101511

1511-
$this->assertContains('Accept-Language: zh, en-us; q=0.8, en; q=0.6', $request->__toString());
1512+
$asString = (string) $request;
1513+
1514+
$this->assertContains('Accept-Language: zh, en-us; q=0.8, en; q=0.6', $asString);
1515+
$this->assertContains('Cookie: Foo=Bar', $asString);
1516+
1517+
$request->cookies->set('Another', 'Cookie');
1518+
1519+
$asString = (string) $request;
1520+
1521+
$this->assertContains('Cookie: Foo=Bar; Another=Cookie', $asString);
15121522
}
15131523

15141524
public function testIsMethod()

src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,22 @@ protected function findClass($file)
111111
}
112112

113113
if (T_CLASS === $token[0]) {
114-
// Skip usage of ::class constant
115-
$isClassConstant = false;
114+
// Skip usage of ::class constant and anonymous classes
115+
$skipClassToken = false;
116116
for ($j = $i - 1; $j > 0; --$j) {
117117
if (!isset($tokens[$j][1])) {
118118
break;
119119
}
120120

121-
if (T_DOUBLE_COLON === $tokens[$j][0]) {
122-
$isClassConstant = true;
121+
if (T_DOUBLE_COLON === $tokens[$j][0] || T_NEW === $tokens[$j][0]) {
122+
$skipClassToken = true;
123123
break;
124124
} elseif (!in_array($tokens[$j][0], array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT))) {
125125
break;
126126
}
127127
}
128128

129-
if (!$isClassConstant) {
129+
if (!$skipClassToken) {
130130
$class = true;
131131
}
132132
}

src/Symfony/Component/Routing/RouteCollectionBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ public function import($resource, $prefix = '/', $type = null)
7676
foreach ($collection->getResources() as $resource) {
7777
$builder->addResource($resource);
7878
}
79-
80-
// mount into this builder
81-
$this->mount($prefix, $builder);
8279
}
8380

81+
// mount into this builder
82+
$this->mount($prefix, $builder);
83+
8484
return $builder;
8585
}
8686

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Routing\Tests\Fixtures\OtherAnnotatedClasses;
13+
14+
trait AnonymousClassInTrait
15+
{
16+
public function test()
17+
{
18+
return new class() {
19+
public function foo()
20+
{
21+
}
22+
};
23+
}
24+
}

0 commit comments

Comments
 (0)