From a3131882e328fc17eb62f0dd4a89e1d7642fad99 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 10 Feb 2013 12:34:10 +0100 Subject: [PATCH 01/22] added a proper setter for the templating servicein HInclude --- .../ContainerAwareHIncludeFragmentRenderer.php | 2 +- .../Fragment/HIncludeFragmentRenderer.php | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Fragment/ContainerAwareHIncludeFragmentRenderer.php b/src/Symfony/Bundle/FrameworkBundle/Fragment/ContainerAwareHIncludeFragmentRenderer.php index db54106358..da273cd7a7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Fragment/ContainerAwareHIncludeFragmentRenderer.php +++ b/src/Symfony/Bundle/FrameworkBundle/Fragment/ContainerAwareHIncludeFragmentRenderer.php @@ -41,7 +41,7 @@ class ContainerAwareHIncludeFragmentRenderer extends HIncludeFragmentRenderer public function render($uri, Request $request, array $options = array()) { if (!$this->templating) { - $this->templating = $this->container->get('templating'); + $this->setTemplating($this->container->get('templating')); } return parent::render($uri, $request, $options); diff --git a/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php b/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php index bd057169b0..1f6c2634bf 100644 --- a/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php +++ b/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php @@ -24,10 +24,9 @@ use Symfony\Component\HttpKernel\UriSigner; */ class HIncludeFragmentRenderer extends RoutableFragmentRenderer { - protected $templating; - private $globalDefaultTemplate; private $signer; + private $templating; /** * Constructor. @@ -37,14 +36,24 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer * @param string $globalDefaultTemplate The global default content (it can be a template name or the content) */ public function __construct($templating = null, UriSigner $signer = null, $globalDefaultTemplate = null) + { + $this->setTemplating($templating); + $this->globalDefaultTemplate = $globalDefaultTemplate; + $this->signer = $signer; + } + + /** + * Sets the templating engine to use to render the default content. + * + * @param EngineInterface|\Twig_Environment|null $templating An EngineInterface or a \Twig_Environment instance + */ + public function setTemplating($templating) { if (null !== $templating && !$templating instanceof EngineInterface && !$templating instanceof \Twig_Environment) { throw new \InvalidArgumentException('The hinclude rendering strategy needs an instance of \Twig_Environment or Symfony\Component\Templating\EngineInterface'); } $this->templating = $templating; - $this->globalDefaultTemplate = $globalDefaultTemplate; - $this->signer = $signer; } /** From d41fc8bb2dd8f20c36daa9b4064a557c2792a926 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 11 Feb 2013 12:41:20 +0100 Subject: [PATCH 02/22] [DependencyInjection] fixed tests (refs #7017) --- .../DependencyInjection}/Fixtures/containers/container13.php | 5 ++++- .../DependencyInjection}/Fixtures/containers/container14.php | 0 .../DependencyInjection}/Fixtures/graphviz/services13.dot | 2 ++ .../DependencyInjection}/Fixtures/graphviz/services14.dot | 0 4 files changed, 6 insertions(+), 1 deletion(-) rename {src/Symfony/Component/DependencyInjection/Tests => tests/Symfony/Tests/Component/DependencyInjection}/Fixtures/containers/container13.php (70%) rename {src/Symfony/Component/DependencyInjection/Tests => tests/Symfony/Tests/Component/DependencyInjection}/Fixtures/containers/container14.php (100%) rename {src/Symfony/Component/DependencyInjection/Tests => tests/Symfony/Tests/Component/DependencyInjection}/Fixtures/graphviz/services13.dot (75%) rename {src/Symfony/Component/DependencyInjection/Tests => tests/Symfony/Tests/Component/DependencyInjection}/Fixtures/graphviz/services14.dot (100%) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container13.php b/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container13.php similarity index 70% rename from src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container13.php rename to tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container13.php index 17b32cf512..cc716c78f0 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container13.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container13.php @@ -1,13 +1,16 @@ register('foo', 'FooClass')-> addArgument(new Reference('bar')) ; +$container-> + register('bar', 'BarClass') +; $container->compile(); return $container; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container14.php b/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container14.php similarity index 100% rename from src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container14.php rename to tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container14.php diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services13.dot b/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/graphviz/services13.dot similarity index 75% rename from src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services13.dot rename to tests/Symfony/Tests/Component/DependencyInjection/Fixtures/graphviz/services13.dot index 4fbcceef36..bc7f81317e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services13.dot +++ b/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/graphviz/services13.dot @@ -4,5 +4,7 @@ digraph sc { edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"]; node_foo [label="foo\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"]; + node_bar [label="bar\nBarClass\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"]; + node_foo -> node_bar [label="" style="filled"]; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services14.dot b/tests/Symfony/Tests/Component/DependencyInjection/Fixtures/graphviz/services14.dot similarity index 100% rename from src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services14.dot rename to tests/Symfony/Tests/Component/DependencyInjection/Fixtures/graphviz/services14.dot From f410931dd808cc7054599ba8fcb3d02e55b43584 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 11 Feb 2013 13:46:49 +0100 Subject: [PATCH 03/22] Revert "merged branch povilas/issue_6101 (PR #6708)" This reverts commit b2bcbbbd19efdb6e4f2133dfbdf162c9bb30a214, reversing changes made to c5fcf0d0cc6a3353ec13e2141411e082693db2d5. --- .../HttpFoundation/BinaryFileResponse.php | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php index 9f5bb21971..cb6c8a1e8a 100644 --- a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php +++ b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php @@ -22,7 +22,6 @@ use Symfony\Component\HttpFoundation\File\Exception\FileException; * @author Igor Wiedler * @author Jordan Alliot * @author Sergey Linnik - * @author Povilas Skruibis */ class BinaryFileResponse extends Response { @@ -124,23 +123,11 @@ class BinaryFileResponse extends Response */ public function setAutoEtag() { - $this->setEtag($this->calculateFileHash($this->file->getPathname())); + $this->setEtag(sha1_file($this->file->getPathname())); return $this; } - /** - * Calculate file hash - * - * @param string $filename The path to the file - * - * @return string - */ - protected function calculateFileHash($filename) - { - return sha1_file($filename); - } - /** * Sets the Content-Disposition header with the given filename. * From a4ac5e6374fe27ef68031e743447700fde348341 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 11 Feb 2013 16:24:43 +0100 Subject: [PATCH 04/22] bumped Symfony version to 2.2.0-DEV --- src/Symfony/Component/HttpKernel/Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 6d3e7061d3..46440a3468 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -62,12 +62,12 @@ abstract class Kernel implements KernelInterface, TerminableInterface protected $classes; protected $errorReportingLevel; - const VERSION = '2.2.0-RC2'; + const VERSION = '2.2.0-DEV'; const VERSION_ID = '20100'; const MAJOR_VERSION = '2'; const MINOR_VERSION = '2'; const RELEASE_VERSION = '0'; - const EXTRA_VERSION = 'RC2'; + const EXTRA_VERSION = 'DEV'; /** * Constructor. From 06c26dc7edad0f678d2c978f425a8793bb99d9a8 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 13 Feb 2013 02:30:42 +0100 Subject: [PATCH 05/22] Remove array type hint from GetResponseForControllerResultEvent::setControllerResult() --- .../HttpKernel/Event/GetResponseForControllerResultEvent.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Event/GetResponseForControllerResultEvent.php b/src/Symfony/Component/HttpKernel/Event/GetResponseForControllerResultEvent.php index a71f504d99..1bc0f98fd0 100644 --- a/src/Symfony/Component/HttpKernel/Event/GetResponseForControllerResultEvent.php +++ b/src/Symfony/Component/HttpKernel/Event/GetResponseForControllerResultEvent.php @@ -56,11 +56,11 @@ class GetResponseForControllerResultEvent extends GetResponseEvent /** * Assigns the return value of the controller. * - * @param array The controller return value + * @param mixed The controller return value * * @api */ - public function setControllerResult(array $controllerResult) + public function setControllerResult($controllerResult) { $this->controllerResult = $controllerResult; } From b240d1f807110d8df9274c867f0246ce9bce918f Mon Sep 17 00:00:00 2001 From: Sebastiaan Stok Date: Wed, 13 Feb 2013 09:37:02 +0100 Subject: [PATCH 06/22] [BrowserKit] added a test to make sure HTTP authentication is preserved when submitting a form --- .../Component/BrowserKit/Tests/ClientTest.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php index e03b73cf0b..e298f0e19b 100644 --- a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php @@ -262,6 +262,37 @@ class ClientTest extends \PHPUnit_Framework_TestCase $this->assertEquals('http://www.example.com/foo', $client->getRequest()->getUri(), '->submit() submit forms'); } + public function testSubmitPreserveAuth() + { + if (!class_exists('Symfony\Component\DomCrawler\Crawler')) { + $this->markTestSkipped('The "DomCrawler" component is not available'); + } + + if (!class_exists('Symfony\Component\CssSelector\CssSelector')) { + $this->markTestSkipped('The "CssSelector" component is not available'); + } + + $client = new TestClient(); + $client->setNextResponse(new Response('
')); + $crawler = $client->request('GET', 'http://www.example.com/foo/foobar', array(), array(), array('PHP_AUTH_USER' => 'foo', 'PHP_AUTH_PW' => 'bar')); + + $server = $client->getRequest()->getServer(); + $this->assertArrayHasKey('PHP_AUTH_USER', $server); + $this->assertEquals('foo', $server['PHP_AUTH_USER']); + $this->assertArrayHasKey('PHP_AUTH_PW', $server); + $this->assertEquals('bar', $server['PHP_AUTH_PW']); + + $client->submit($crawler->filter('input')->form()); + + $this->assertEquals('http://www.example.com/foo', $client->getRequest()->getUri(), '->submit() submit forms'); + + $server = $client->getRequest()->getServer(); + $this->assertArrayHasKey('PHP_AUTH_USER', $server); + $this->assertEquals('foo', $server['PHP_AUTH_USER']); + $this->assertArrayHasKey('PHP_AUTH_PW', $server); + $this->assertEquals('bar', $server['PHP_AUTH_PW']); + } + public function testFollowRedirect() { $client = new TestClient(); From 5e8d84467857d341edc2728285e054e7e370a01d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 14 Feb 2013 12:11:15 +0100 Subject: [PATCH 07/22] [Process] Warn user with a useful message when tmpfile() failed --- src/Symfony/Component/Process/Process.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 4af26e85a2..7f065efe26 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -213,6 +213,9 @@ class Process $this->fileHandles = array( self::STDOUT => tmpfile(), ); + if (false === $this->fileHandles[self::STDOUT]) { + throw new RuntimeException('A temporary file could not be opened to write the process output to, verify that your TEMP environment variable is writable'); + } $this->readBytes = array( self::STDOUT => 0, ); From 3473fc7ae4f857776815e9ff25a6335621edc8bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Lukss?= Date: Thu, 14 Feb 2013 09:35:03 -0800 Subject: [PATCH 08/22] Create validators.lv.xlf Latvian translation of validators --- .../Resources/translations/validators.lv.xlf | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/Symfony/Component/Form/Resources/translations/validators.lv.xlf diff --git a/src/Symfony/Component/Form/Resources/translations/validators.lv.xlf b/src/Symfony/Component/Form/Resources/translations/validators.lv.xlf new file mode 100644 index 0000000000..9cdfb2cd48 --- /dev/null +++ b/src/Symfony/Component/Form/Resources/translations/validators.lv.xlf @@ -0,0 +1,19 @@ + + + + + + This form should not contain extra fields. + Šajā veidlapā nevajadzētu būt papildus ievades laukiem. + + + The uploaded file was too large. Please try to upload a smaller file. + Augšupielādētā faila izmērs bija par lielu. Lūdzu mēģiniet augšupielādēt mazāka izmēra failu. + + + The CSRF token is invalid. Please try to resubmit the form. + Dotais CSRF talons nav derīgs. Lūdzu mēģiniet vēlreiz iesniegt veidlapu. + + + + From de0f7b759f9b8f660d425ed72adc7b193f23c843 Mon Sep 17 00:00:00 2001 From: Florin Patan Date: Thu, 7 Feb 2013 14:10:06 +0200 Subject: [PATCH 09/22] [HttpFoundation] Added getter for httpMethodParameterOverride state --- src/Symfony/Component/HttpFoundation/Request.php | 10 ++++++++++ .../Component/HttpFoundation/Tests/RequestTest.php | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 0815b46eae..3d317f0d4b 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -591,6 +591,16 @@ class Request self::$httpMethodParameterOverride = true; } + /** + * Get the state of httpMethodParameterOverride value. + * + * @return Boolean + */ + public static function getHttpMethodParameterOverride() + { + return self::$httpMethodParameterOverride; + } + /** * Gets a "parameter" value. * diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 9f4cb57571..6347df176a 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -677,7 +677,13 @@ class RequestTest extends \PHPUnit_Framework_TestCase $request = new Request(); $request->setMethod('POST'); $request->request->set('_method', 'purge'); + + $this->assertFalse(Request::getHttpMethodParameterOverride(), 'httpMethodParameterOverride should be disabled by default'); + Request::enableHttpMethodParameterOverride(); + + $this->assertTrue(Request::getHttpMethodParameterOverride(), 'httpMethodParameterOverride should be enabled now but it is not'); + $this->assertEquals('PURGE', $request->getMethod(), '->getMethod() returns the method from _method if defined and POST'); $this->disableHttpMethodParameterOverride(); From 5276a096a6adad36d03ebf882973de9371d319a7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 15 Feb 2013 08:36:52 +0100 Subject: [PATCH 10/22] [HttpFoundation] tweaked previous merge --- src/Symfony/Component/HttpFoundation/CHANGELOG.md | 3 ++- src/Symfony/Component/HttpFoundation/Request.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/CHANGELOG.md b/src/Symfony/Component/HttpFoundation/CHANGELOG.md index 15e0c9cfe4..318383aa56 100644 --- a/src/Symfony/Component/HttpFoundation/CHANGELOG.md +++ b/src/Symfony/Component/HttpFoundation/CHANGELOG.md @@ -10,7 +10,8 @@ CHANGELOG * [BC BREAK] JsonResponse does not turn a top level empty array to an object anymore, use an ArrayObject to enforce objects * added a IpUtils class to check if an IP belongs to a CIDR * added Request::getRealMethod() to get the "real" HTTP method (getMethod() returns the "intended" HTTP method) - * disabled _method request parameter support by default (call Request::enableHttpMethodParameterOverride() to enable it) + * disabled _method request parameter support by default (call Request::enableHttpMethodParameterOverride() to + enable it, and Request::getHttpMethodParameterOverride() to check if it is supported) * Request::splitHttpAcceptHeader() method is deprecated and will be removed in 2.3 * Deprecated Flashbag::count() and \Countable interface, will be removed in 2.3 diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 04faf988f8..ac12d3ce46 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -595,9 +595,9 @@ class Request } /** - * Get the state of httpMethodParameterOverride value. + * Checks whether support for the _method request parameter is enabled. * - * @return Boolean + * @return Boolean True when the _method request parameter is enabled, false otherwise */ public static function getHttpMethodParameterOverride() { From cb319acb11ced9721e8bdfa1e675d4616e788ca2 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 15 Feb 2013 08:54:09 +0100 Subject: [PATCH 11/22] [HttpKernel] added error display suppression when using the ErrorHandler (if not, errors are displayed twice, refs #6254) --- src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php b/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php index c014582d25..3c1cf72d2d 100644 --- a/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php +++ b/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php @@ -58,6 +58,7 @@ class ErrorHandler $handler = new static(); $handler->setLevel($level); + ini_set('display_errors', 0); set_error_handler(array($handler, 'handle')); register_shutdown_function(array($handler, 'handleFatal')); $handler->reservedMemory = str_repeat('x', 10240); From a9f60f70a6d87cc52f1ff5da46afb1b6f2a0a58a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 15 Feb 2013 08:28:01 +0100 Subject: [PATCH 12/22] [WebProfilerBundle] removed dependency on FrameworkBundle (closes #6949) --- .../Controller/ProfilerController.php | 12 ++++++++++++ .../Resources/config/routing/profiler.xml | 14 ++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index 7e04c70729..1b2d8ded1f 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -52,6 +52,18 @@ class ProfilerController $this->toolbarPosition = $toolbarPosition; } + /** + * Redirects to the last profiles. + * + * @return RedirectResponse A RedirectResponse instance + */ + public function homeAction() + { + $this->profiler->disable(); + + return new RedirectResponse($this->generator->generate('_profiler_search_results', array('token' => 'empty', 'limit' => 10))); + } + /** * Renders a profiler panel for the given token. * diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.xml b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.xml index 968ab8f3cb..1819e481c8 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.xml +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.xml @@ -4,6 +4,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> + + web_profiler.controller.profiler:homeAction + + web_profiler.controller.profiler:searchAction @@ -52,14 +56,4 @@ web_profiler.controller.exception:cssAction - - FrameworkBundle:Redirect:redirect - _profiler_search_results - empty - - - - 10 - - From f842ae6d99829bbf10201317cc16c217b747b804 Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 13 Feb 2013 12:09:10 +0100 Subject: [PATCH 13/22] [FrameworkBundle] CSRF should be on by default --- .../FrameworkBundle/DependencyInjection/Configuration.php | 2 +- .../Tests/DependencyInjection/ConfigurationTest.php | 2 +- .../Tests/DependencyInjection/Fixtures/yml/csrf.yml | 6 ++++++ .../DependencyInjection/YamlFrameworkExtensionTest.php | 7 +++++++ 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/csrf.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 557dc39414..fe3c3501d5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -94,7 +94,7 @@ class Configuration implements ConfigurationInterface ->canBeEnabled() ->end() ->arrayNode('csrf_protection') - ->canBeEnabled() + ->canBeDisabled() ->children() ->scalarNode('field_name')->defaultValue('_token')->end() ->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 305f4e2dee..3c6c0ea475 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -94,7 +94,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase 'default_locale' => 'en', 'form' => array('enabled' => false), 'csrf_protection' => array( - 'enabled' => false, + 'enabled' => true, 'field_name' => '_token', ), 'esi' => array('enabled' => false), diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/csrf.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/csrf.yml new file mode 100644 index 0000000000..ce5fc591ed --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/csrf.yml @@ -0,0 +1,6 @@ +framework: + secret: s3cr3t + form: ~ + session: ~ + # CSRF should be enabled by default + # csrf_protection: ~ diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/YamlFrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/YamlFrameworkExtensionTest.php index 43070c00c9..b8dcefc558 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/YamlFrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/YamlFrameworkExtensionTest.php @@ -22,4 +22,11 @@ class YamlFrameworkExtensionTest extends FrameworkExtensionTest $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/yml')); $loader->load($file.'.yml'); } + + public function testCsrfProtectionShouldBeEnabledByDefault() + { + $container = $this->createContainerFromFile('csrf'); + + $this->assertTrue($container->getParameter('form.type_extension.csrf.enabled')); + } } From 0eff68f8c8058306bcce31ac628d89c5aad22114 Mon Sep 17 00:00:00 2001 From: Michel Weimerskirch Date: Sat, 16 Feb 2013 11:47:41 +0100 Subject: [PATCH 14/22] Fix REMOTE_ADDR for cached subrequests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #7091 --- .../HttpKernel/HttpCache/HttpCache.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php index 97e365008b..ae918e1543 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php @@ -413,18 +413,6 @@ class HttpCache implements HttpKernelInterface, TerminableInterface $subRequest->headers->remove('if_modified_since'); $subRequest->headers->remove('if_none_match'); - // modify the X-Forwarded-For header if needed - $forwardedFor = $subRequest->headers->get('X-Forwarded-For'); - if ($forwardedFor) { - $subRequest->headers->set('X-Forwarded-For', $forwardedFor.', '.$subRequest->server->get('REMOTE_ADDR')); - } else { - $subRequest->headers->set('X-Forwarded-For', $subRequest->server->get('REMOTE_ADDR')); - } - - // fix the client IP address by setting it to 127.0.0.1 as HttpCache - // is always called from the same process as the backend. - $subRequest->server->set('REMOTE_ADDR', '127.0.0.1'); - $response = $this->forward($subRequest, $catch); if ($this->isPrivateRequest($request) && !$response->headers->hasCacheControlDirective('public')) { @@ -455,6 +443,18 @@ class HttpCache implements HttpKernelInterface, TerminableInterface $this->esi->addSurrogateEsiCapability($request); } + // modify the X-Forwarded-For header if needed + $forwardedFor = $request->headers->get('X-Forwarded-For'); + if ($forwardedFor) { + $request->headers->set('X-Forwarded-For', $forwardedFor.', '.$request->server->get('REMOTE_ADDR')); + } else { + $request->headers->set('X-Forwarded-For', $request->server->get('REMOTE_ADDR')); + } + + // fix the client IP address by setting it to 127.0.0.1 as HttpCache + // is always called from the same process as the backend. + $request->server->set('REMOTE_ADDR', '127.0.0.1'); + // always a "master" request (as the real master request can be in cache) $response = $this->kernel->handle($request, HttpKernelInterface::MASTER_REQUEST, $catch); // FIXME: we probably need to also catch exceptions if raw === true From 98d57500f26a2d0bb6d584ad4fe602a333403719 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 17 Feb 2013 12:42:54 +0100 Subject: [PATCH 15/22] [HttpKernel] added some tests for previous merge --- .../HttpKernel/Tests/HttpCache/HttpCacheTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php index 89203a8ae2..4cdd5f60e1 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php @@ -1066,4 +1066,13 @@ class HttpCacheTest extends HttpCacheTestCase array('10.0.0.2, 10.0.0.3', '10.0.0.2, 10.0.0.3, 10.0.0.1'), ); } + + public function testXForwarderForHeaderForPassRequests() + { + $this->setNextResponse(); + $server = array('REMOTE_ADDR' => '10.0.0.1'); + $this->request('POST', '/', $server); + + $this->assertEquals('10.0.0.1', $this->kernel->getBackendRequest()->headers->get('X-Forwarded-For')); + } } From 609636e95ed970c052b77a8f178da46989da44ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Egyed?= Date: Sat, 16 Feb 2013 23:02:39 +0100 Subject: [PATCH 16/22] [Config] tweaked dumper to indent multi-line info --- .../Config/Definition/ReferenceDumper.php | 4 +- .../Tests/Definition/ReferenceDumperTest.php | 62 +++++++++++++++++ .../Configuration/ExampleConfiguration.php | 67 +++++++++++++++++++ 3 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/Config/Tests/Definition/ReferenceDumperTest.php create mode 100644 src/Symfony/Component/Config/Tests/Fixtures/Configuration/ExampleConfiguration.php diff --git a/src/Symfony/Component/Config/Definition/ReferenceDumper.php b/src/Symfony/Component/Config/Definition/ReferenceDumper.php index 3230c01931..ef2b05d10f 100644 --- a/src/Symfony/Component/Config/Definition/ReferenceDumper.php +++ b/src/Symfony/Component/Config/Definition/ReferenceDumper.php @@ -115,10 +115,12 @@ class ReferenceDumper $default = (string) $default != '' ? ' '.$default : ''; $comments = count($comments) ? '# '.implode(', ', $comments) : ''; - $text = sprintf('%-20s %s %s', $node->getName().':', $default, $comments); + $text = rtrim(sprintf('%-20s %s %s', $node->getName() . ':', $default, $comments), ' '); if ($info = $node->getInfo()) { $this->writeLine(''); + // indenting multi-line info + $info = str_replace("\n", sprintf("\n%" . $depth * 4 . "s# ", ' '), $info); $this->writeLine('# '.$info, $depth * 4); } diff --git a/src/Symfony/Component/Config/Tests/Definition/ReferenceDumperTest.php b/src/Symfony/Component/Config/Tests/Definition/ReferenceDumperTest.php new file mode 100644 index 0000000000..137caf8cbc --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Definition/ReferenceDumperTest.php @@ -0,0 +1,62 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Config\Tests\Definition; + +use Symfony\Component\Config\Definition\ReferenceDumper; +use Symfony\Component\Config\Tests\Fixtures\Configuration\ExampleConfiguration; + +class ReferenceDumperTest extends \PHPUnit_Framework_TestCase +{ + public function testDumper() + { + $configuration = new ExampleConfiguration(); + + $dumper = new ReferenceDumper(); + $this->assertEquals($this->getConfigurationAsString(), $dumper->dump($configuration)); + } + + private function getConfigurationAsString() + { + return << + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Config\Tests\Fixtures\Configuration; + +use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; + +class ExampleConfiguration implements ConfigurationInterface +{ + public function getConfigTreeBuilder() + { + $treeBuilder = new TreeBuilder(); + $rootNode = $treeBuilder->root('root'); + + $rootNode + ->children() + ->booleanNode('boolean')->defaultTrue()->end() + ->scalarNode('scalar_empty')->end() + ->scalarNode('scalar_null')->defaultNull()->end() + ->scalarNode('scalar_true')->defaultTrue()->end() + ->scalarNode('scalar_false')->defaultFalse()->end() + ->scalarNode('scalar_default')->defaultValue('default')->end() + ->scalarNode('scalar_array_empty')->defaultValue(array())->end() + ->scalarNode('scalar_array_defaults')->defaultValue(array('elem1', 'elem2'))->end() + ->arrayNode('array') + ->info('some info') + ->canBeUnset() + ->children() + ->scalarNode('child1')->end() + ->scalarNode('child2')->end() + ->scalarNode('child3') + ->info( + "this is a long\n". + "multi-line info text\n". + "which should be indented" + ) + ->example('example setting') + ->end() + ->end() + ->end() + ->arrayNode('array_prototype') + ->children() + ->arrayNode('parameters') + ->useAttributeAsKey('name') + ->prototype('array') + ->children() + ->scalarNode('value')->isRequired()->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ; + + return $treeBuilder; + } +} From 22aa8a6f669fc72d7dd9723318e2dc76942ec970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20=C5=81ukaszewicz?= Date: Tue, 12 Feb 2013 18:53:25 +0100 Subject: [PATCH 17/22] Remove unnecessary comment and change test name --- .../Form/Tests/Extension/Core/Type/ChoiceTypeTest.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index 3b32ab38e8..844715c650 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -86,10 +86,7 @@ class ChoiceTypeTest extends TypeTestCase )); } - /** - * expectedException \Symfony\Component\Form\Exception\Exception - */ - public function testEitherChoiceListOrChoicesMustBeSet() + public function testChoiceListAndChoicesCanBeEmpty() { $this->factory->create('choice', null, array( )); From 18b139d41c5f3c2993182c3cff795db661da87bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Egyed?= Date: Sun, 17 Feb 2013 13:49:11 +0100 Subject: [PATCH 18/22] [FrameworkBundle] tweaked reference dumper command (see #7093) --- .../FrameworkBundle/Command/ConfigDumpReferenceCommand.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php index d735eac337..688e0fdbd7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php @@ -236,10 +236,12 @@ EOF $default = (string) $default != '' ? ' '.$default : ''; $comments = count($comments) ? '# '.implode(', ', $comments) : ''; - $text = sprintf('%-20s %s %s', $node->getName().':', $default, $comments); + $text = rtrim(sprintf('%-20s %s %s', $node->getName() . ':', $default, $comments), ' '); if ($info = $node->getInfo()) { $this->outputLine(''); + // indenting multi-line info + $info = str_replace("\n", sprintf("\n%" . $depth * 4 . "s# ", ' '), $info); $this->outputLine('# '.$info, $depth * 4); } From 5bf6d7e1b8a7c5e1eddd27e0a37d27a9e67b7010 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 17 Feb 2013 13:53:31 +0100 Subject: [PATCH 19/22] [BrowserKit] fixed test added in the previous merge (refs #7059) --- src/Symfony/Component/BrowserKit/Tests/ClientTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php index e298f0e19b..32a3889a4b 100644 --- a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php @@ -272,9 +272,9 @@ class ClientTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('The "CssSelector" component is not available'); } - $client = new TestClient(); + $client = new TestClient(array('PHP_AUTH_USER' => 'foo', 'PHP_AUTH_PW' => 'bar')); $client->setNextResponse(new Response('
')); - $crawler = $client->request('GET', 'http://www.example.com/foo/foobar', array(), array(), array('PHP_AUTH_USER' => 'foo', 'PHP_AUTH_PW' => 'bar')); + $crawler = $client->request('GET', 'http://www.example.com/foo/foobar'); $server = $client->getRequest()->getServer(); $this->assertArrayHasKey('PHP_AUTH_USER', $server); From d0e4b7639cc62f3dcfcb35a0016a4de6d9c70bca Mon Sep 17 00:00:00 2001 From: Martijn Evers Date: Fri, 8 Feb 2013 16:29:55 +0100 Subject: [PATCH 20/22] [HttpFoundation] fixed, overwritten CONTENT_TYPE --- src/Symfony/Component/HttpFoundation/Request.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index ac12d3ce46..867a29b6af 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -325,7 +325,9 @@ class Request case 'POST': case 'PUT': case 'DELETE': - $server['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; + if (!isset($server['CONTENT_TYPE'])) { + $server['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; + } case 'PATCH': $request = $parameters; $query = array(); From 738de9a24698d33fd31e55f59ccfefe35b433f66 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 17 Feb 2013 14:09:02 +0100 Subject: [PATCH 21/22] [HttpKernel] added a unit for the previous commit (closes #7025) --- src/Symfony/Component/HttpFoundation/Tests/RequestTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index b47af11607..a232c25b20 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -228,13 +228,14 @@ class RequestTest extends \PHPUnit_Framework_TestCase public function testCreateCheckPrecedence() { // server is used by default - $request = Request::create('/', 'GET', array(), array(), array(), array( + $request = Request::create('/', 'DELETE', array(), array(), array(), array( 'HTTP_HOST' => 'example.com', 'HTTPS' => 'on', 'SERVER_PORT' => 443, 'PHP_AUTH_USER' => 'fabien', 'PHP_AUTH_PW' => 'pa$$', 'QUERY_STRING' => 'foo=bar', + 'CONTENT_TYPE' => 'application/json', )); $this->assertEquals('example.com', $request->getHost()); $this->assertEquals(443, $request->getPort()); @@ -242,6 +243,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase $this->assertEquals('fabien', $request->getUser()); $this->assertEquals('pa$$', $request->getPassword()); $this->assertEquals('', $request->getQueryString()); + $this->assertEquals('application/json', $request->headers->get('CONTENT_TYPE')); // URI has precedence over server $request = Request::create('http://thomas:pokemon@example.net:8080/?foo=bar', 'GET', array(), array(), array(), array( From 179cd586466d7d31acd67be9e7c75d52488915f7 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 17 Feb 2013 20:36:23 +0100 Subject: [PATCH 22/22] [Process] Fix regression introduced in #6620 / 880da01c49a9255f5022ab7e18bca38c18f56370, fixes #7082 --- src/Symfony/Component/Process/Process.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index cf553ee11a..a506e0c33e 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -54,6 +54,10 @@ class Process $this->commandline = $commandline; $this->cwd = $cwd; + // on windows, if the cwd changed via chdir(), proc_open defaults to the dir where php was started + if (null === $this->cwd && defined('PHP_WINDOWS_VERSION_BUILD')) { + $this->cwd = getcwd(); + } if (null !== $env) { $this->env = array(); foreach ($env as $key => $value) {