From ddf4678dd6b9e6e3d0f625c8b1398f7f5ce034f1 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Feb 2013 19:34:47 +0100 Subject: [PATCH 01/14] [HttpFoundation] fixed the creation of sub-requests under some circumstancies (closes #6923, closes #6936) This fixes the creation of a sub-request when the master request Request URI is determined with specific server information. --- src/Symfony/Component/HttpFoundation/Request.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index f973583125..b033a4f2fa 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1201,12 +1201,16 @@ class Request if ($this->headers->has('X_ORIGINAL_URL') && false !== stripos(PHP_OS, 'WIN')) { // IIS with Microsoft Rewrite Module $requestUri = $this->headers->get('X_ORIGINAL_URL'); + $this->headers->remove('X_ORIGINAL_URL'); } elseif ($this->headers->has('X_REWRITE_URL') && false !== stripos(PHP_OS, 'WIN')) { // IIS with ISAPI_Rewrite $requestUri = $this->headers->get('X_REWRITE_URL'); + $this->headers->remove('X_REWRITE_URL'); } elseif ($this->server->get('IIS_WasUrlRewritten') == '1' && $this->server->get('UNENCODED_URL') != '') { // IIS7 with URL Rewrite: make sure we get the unencoded url (double slash problem) $requestUri = $this->server->get('UNENCODED_URL'); + $this->server->remove('UNENCODED_URL'); + $this->server->remove('IIS_WasUrlRewritten'); } elseif ($this->server->has('REQUEST_URI')) { $requestUri = $this->server->get('REQUEST_URI'); // HTTP proxy reqs setup request uri with scheme and host [and port] + the url path, only use url path @@ -1220,8 +1224,12 @@ class Request if ($this->server->get('QUERY_STRING')) { $requestUri .= '?'.$this->server->get('QUERY_STRING'); } + $this->server->remove('ORIG_PATH_INFO'); } + // normalize the request URI to ease creating sub-requests from this request + $this->server->set('REQUEST_URI', $requestUri); + return $requestUri; } From a12744e30e81294d5b0cab821b959b96bce358c8 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 7 Feb 2013 17:24:12 +0100 Subject: [PATCH 02/14] Add dot character `.` to legal mime subtype regular expression --- .../HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php b/src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php index 115d95deef..aa69ea6c58 100644 --- a/src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php +++ b/src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php @@ -61,7 +61,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface $type = trim(ob_get_clean()); - if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-]+)#i', $type, $match)) { + if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\.]+)#i', $type, $match)) { // it's not a type, but an error message return null; } From 73aa7d128b23a0124a97d4df56d3be8418ff3b34 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 6 Feb 2013 22:52:59 +0100 Subject: [PATCH 03/14] replaced usage of the deprecated pattern routing key (replaced with path) --- .../TestBundle/Resources/config/routing.yml | 12 +++++----- .../Resources/config/routing.yml | 16 ++++++------- .../Resources/config/localized_routing.yml | 12 +++++----- .../Resources/config/routing.yml | 18 +++++++-------- .../Fixtures/nonesense_resource_plus_path.yml | 2 +- .../nonesense_type_without_resource.yml | 2 +- .../Tests/Fixtures/special_route_name.yml | 2 +- .../Routing/Tests/Fixtures/validpattern.php | 11 ++++++++- .../Routing/Tests/Fixtures/validpattern.xml | 9 +++++++- .../Routing/Tests/Fixtures/validpattern.yml | 16 ++++++++++--- .../Tests/Loader/PhpFileLoaderTest.php | 17 ++++++++------ .../Tests/Loader/XmlFileLoaderTest.php | 23 +++++++++++-------- .../Tests/Loader/YamlFileLoaderTest.php | 21 +++++++++-------- 13 files changed, 99 insertions(+), 62 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml index 2a077856f6..d9b380ef8d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml @@ -1,23 +1,23 @@ session_welcome: - pattern: /session + path: /session defaults: { _controller: TestBundle:Session:welcome } session_welcome_name: - pattern: /session/{name} + path: /session/{name} defaults: { _controller: TestBundle:Session:welcome } session_logout: - pattern: /session_logout + path: /session_logout defaults: { _controller: TestBundle:Session:logout} session_setflash: - pattern: /session_setflash/{message} + path: /session_setflash/{message} defaults: { _controller: TestBundle:Session:setFlash} session_showflash: - pattern: /session_showflash + path: /session_showflash defaults: { _controller: TestBundle:Session:showFlash} profiler: - pattern: /profiler + path: /profiler defaults: { _controller: TestBundle:Profiler:index } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Resources/config/routing.yml b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Resources/config/routing.yml index 0c9842bb9a..0a02730233 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Resources/config/routing.yml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Resources/config/routing.yml @@ -1,30 +1,30 @@ form_login: - pattern: /login + path: /login defaults: { _controller: CsrfFormLoginBundle:Login:login } form_login_check: - pattern: /login_check + path: /login_check defaults: { _controller: CsrfFormLoginBundle:Login:loginCheck } form_login_homepage: - pattern: / + path: / defaults: { _controller: CsrfFormLoginBundle:Login:afterLogin } form_login_custom_target_path: - pattern: /foo + path: /foo defaults: { _controller: CsrfFormLoginBundle:Login:afterLogin } form_login_default_target_path: - pattern: /profile + path: /profile defaults: { _controller: CsrfFormLoginBundle:Login:afterLogin } form_login_redirect_to_protected_resource_after_login: - pattern: /protected-resource + path: /protected-resource defaults: { _controller: CsrfFormLoginBundle:Login:afterLogin } form_logout: - pattern: /logout_path + path: /logout_path form_secure_action: - pattern: /secure-but-not-covered-by-access-control + path: /secure-but-not-covered-by-access-control defaults: { _controller: CsrfFormLoginBundle:Login:secure } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Resources/config/localized_routing.yml b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Resources/config/localized_routing.yml index a10bf9e101..964a74fe89 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Resources/config/localized_routing.yml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Resources/config/localized_routing.yml @@ -1,29 +1,29 @@ localized_login_path: - pattern: /{_locale}/login + path: /{_locale}/login defaults: { _controller: FormLoginBundle:Localized:login } requirements: { _locale: "^[a-z]{2}$" } localized_check_path: - pattern: /{_locale}/login_check + path: /{_locale}/login_check defaults: { _controller: FormLoginBundle:Localized:loginCheck } requirements: { _locale: "^[a-z]{2}$" } localized_default_target_path: - pattern: /{_locale}/profile + path: /{_locale}/profile defaults: { _controller: FormLoginBundle:Localized:profile } requirements: { _locale: "^[a-z]{2}$" } localized_logout_path: - pattern: /{_locale}/logout + path: /{_locale}/logout defaults: { _controller: FormLoginBundle:Localized:logout } requirements: { _locale: "^[a-z]{2}$" } localized_logout_target_path: - pattern: /{_locale}/ + path: /{_locale}/ defaults: { _controller: FormLoginBundle:Localized:homepage } requirements: { _locale: "^[a-z]{2}$" } localized_secure_path: - pattern: /{_locale}/secure/ + path: /{_locale}/secure/ defaults: { _controller: FormLoginBundle:Localized:secure } requirements: { _locale: "^[a-z]{2}$" } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Resources/config/routing.yml b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Resources/config/routing.yml index c9684cec51..13788e1f96 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Resources/config/routing.yml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Resources/config/routing.yml @@ -1,33 +1,33 @@ form_login: - pattern: /login + path: /login defaults: { _controller: FormLoginBundle:Login:login } form_login_check: - pattern: /login_check + path: /login_check defaults: { _controller: FormLoginBundle:Login:loginCheck } form_login_homepage: - pattern: / + path: / defaults: { _controller: FormLoginBundle:Login:afterLogin } form_login_custom_target_path: - pattern: /foo + path: /foo defaults: { _controller: FormLoginBundle:Login:afterLogin } form_login_default_target_path: - pattern: /profile + path: /profile defaults: { _controller: FormLoginBundle:Login:afterLogin } form_login_redirect_to_protected_resource_after_login: - pattern: /protected_resource + path: /protected_resource defaults: { _controller: FormLoginBundle:Login:afterLogin } highly_protected_resource: - pattern: /highly_protected_resource + path: /highly_protected_resource form_logout: - pattern: /logout_path + path: /logout_path form_secure_action: - pattern: /secure-but-not-covered-by-access-control + path: /secure-but-not-covered-by-access-control defaults: { _controller: FormLoginBundle:Login:secure } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/nonesense_resource_plus_path.yml b/src/Symfony/Component/Routing/Tests/Fixtures/nonesense_resource_plus_path.yml index eba64e56bb..a3e9473727 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/nonesense_resource_plus_path.yml +++ b/src/Symfony/Component/Routing/Tests/Fixtures/nonesense_resource_plus_path.yml @@ -1,3 +1,3 @@ blog_show: resource: validpattern.yml - pattern: /test + path: /test diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/nonesense_type_without_resource.yml b/src/Symfony/Component/Routing/Tests/Fixtures/nonesense_type_without_resource.yml index 3b4c76898b..547cda3b61 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/nonesense_type_without_resource.yml +++ b/src/Symfony/Component/Routing/Tests/Fixtures/nonesense_type_without_resource.yml @@ -1,3 +1,3 @@ blog_show: - pattern: /blog/{slug} + path: /blog/{slug} type: custom diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/special_route_name.yml b/src/Symfony/Component/Routing/Tests/Fixtures/special_route_name.yml index 1009741a86..78be239aa4 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/special_route_name.yml +++ b/src/Symfony/Component/Routing/Tests/Fixtures/special_route_name.yml @@ -1,2 +1,2 @@ "#$péß^a|": - pattern: "true" + path: "true" diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/validpattern.php b/src/Symfony/Component/Routing/Tests/Fixtures/validpattern.php index 08e7d6e347..9841458a63 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/validpattern.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/validpattern.php @@ -6,9 +6,18 @@ $collection = new RouteCollection(); $collection->add('blog_show', new Route( '/blog/{slug}', array('_controller' => 'MyBlogBundle:Blog:show'), - array('_method' => 'GET', 'locale' => '\w+'), + array('_method' => 'GET', 'locale' => '\w+', '_scheme' => 'https'), array('compiler_class' => 'RouteCompiler'), '{locale}.example.com' )); +$collection->add('blog_show_legacy', new Route( + '/blog/{slug}', + array('_controller' => 'MyBlogBundle:Blog:show'), + array('locale' => '\w+'), + array('compiler_class' => 'RouteCompiler'), + '{locale}.example.com', + array('https'), + array('GET') +)); return $collection; diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/validpattern.xml b/src/Symfony/Component/Routing/Tests/Fixtures/validpattern.xml index eb3aea78b6..df3a256acf 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/validpattern.xml +++ b/src/Symfony/Component/Routing/Tests/Fixtures/validpattern.xml @@ -4,9 +4,16 @@ 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"> - + + MyBundle:Blog:show + \w+ + + + + MyBundle:Blog:show GET + https \w+ diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/validpattern.yml b/src/Symfony/Component/Routing/Tests/Fixtures/validpattern.yml index d78a3e44e7..419923e9c3 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/validpattern.yml +++ b/src/Symfony/Component/Routing/Tests/Fixtures/validpattern.yml @@ -1,7 +1,17 @@ blog_show: - pattern: /blog/{slug} + path: /blog/{slug} defaults: { _controller: MyBlogBundle:Blog:show } - host : "{locale}.example.com" - requirements: { '_method': 'GET', 'locale': '\w+' } + host: "{locale}.example.com" + requirements: { 'locale': '\w+' } + methods: ['GET'] + schemes: ['https'] + options: + compiler_class: RouteCompiler + +blog_show_legacy: + pattern: /blog/{slug} + defaults: { _controller: MyBlogBundle:Blog:show } + host: "{locale}.example.com" + requirements: { '_method': 'GET', 'locale': '\w+', _scheme: 'https' } options: compiler_class: RouteCompiler diff --git a/src/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php index 6cb2456852..7494fb01d9 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php @@ -40,13 +40,16 @@ class PhpFileLoaderTest extends \PHPUnit_Framework_TestCase $routeCollection = $loader->load('validpattern.php'); $routes = $routeCollection->all(); - $this->assertEquals(1, count($routes), 'One route is loaded'); + $this->assertCount(2, $routes, 'Two routes are loaded'); $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes); - $route = $routes['blog_show']; - $this->assertEquals('/blog/{slug}', $route->getPath()); - $this->assertEquals('MyBlogBundle:Blog:show', $route->getDefault('_controller')); - $this->assertEquals('GET', $route->getRequirement('_method')); - $this->assertEquals('{locale}.example.com', $route->getHost()); - $this->assertEquals('RouteCompiler', $route->getOption('compiler_class')); + + foreach ($routes as $route) { + $this->assertEquals('/blog/{slug}', $route->getPath()); + $this->assertEquals('MyBlogBundle:Blog:show', $route->getDefault('_controller')); + $this->assertEquals('GET', $route->getRequirement('_method')); + $this->assertEquals('https', $route->getRequirement('_scheme')); + $this->assertEquals('{locale}.example.com', $route->getHost()); + $this->assertEquals('RouteCompiler', $route->getOption('compiler_class')); + } } } diff --git a/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php index e40468247d..b67ebf3486 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php @@ -41,12 +41,13 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase $routeCollection = $loader->load('validpattern.xml'); $routes = $routeCollection->all(); - $this->assertEquals(1, count($routes), 'One route is loaded'); + $this->assertCount(2, $routes, 'Two routes are loaded'); $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes); $route = $routes['blog_show']; $this->assertEquals('/blog/{slug}', $route->getPath()); $this->assertEquals('MyBundle:Blog:show', $route->getDefault('_controller')); $this->assertEquals('GET', $route->getRequirement('_method')); + $this->assertEquals('https', $route->getRequirement('_scheme')); $this->assertEquals('\w+', $route->getRequirement('locale')); $this->assertEquals('{locale}.example.com', $route->getHost()); $this->assertEquals('RouteCompiler', $route->getOption('compiler_class')); @@ -57,7 +58,8 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures'))); $routeCollection = $loader->load('namespaceprefix.xml'); - $this->assertCount(1, $routeCollection, 'One route is loaded'); + $this->assertCount(1, $routeCollection->all(), 'One route is loaded'); + $route = $routeCollection->get('blog_show'); $this->assertEquals('/blog/{slug}', $route->getPath()); $this->assertEquals('MyBundle:Blog:show', $route->getDefault('_controller')); @@ -73,14 +75,17 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase $routeCollection = $loader->load('validresource.xml'); $routes = $routeCollection->all(); - $this->assertEquals(1, count($routes), 'One route is loaded'); + $this->assertCount(2, $routes, 'Two routes are loaded'); $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes); - $this->assertEquals('/{foo}/blog/{slug}', $routes['blog_show']->getPath()); - $this->assertEquals('MyBundle:Blog:show', $routes['blog_show']->getDefault('_controller')); - $this->assertEquals('123', $routes['blog_show']->getDefault('foo')); - $this->assertEquals('\d+', $routes['blog_show']->getRequirement('foo')); - $this->assertEquals('bar', $routes['blog_show']->getOption('foo')); - $this->assertEquals('{locale}.example.com', $routes['blog_show']->getHost()); + + foreach ($routes as $route) { + $this->assertEquals('/{foo}/blog/{slug}', $routes['blog_show']->getPath()); + $this->assertEquals('MyBundle:Blog:show', $routes['blog_show']->getDefault('_controller')); + $this->assertEquals('123', $routes['blog_show']->getDefault('foo')); + $this->assertEquals('\d+', $routes['blog_show']->getRequirement('foo')); + $this->assertEquals('bar', $routes['blog_show']->getOption('foo')); + $this->assertEquals('{locale}.example.com', $routes['blog_show']->getHost()); + } } /** diff --git a/src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php index bb055de4e7..b6234bf8e5 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php @@ -79,15 +79,18 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase $routeCollection = $loader->load('validpattern.yml'); $routes = $routeCollection->all(); - $this->assertEquals(1, count($routes), 'One route is loaded'); + $this->assertCount(2, $routes, 'Two routes are loaded'); $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes); - $route = $routes['blog_show']; - $this->assertEquals('/blog/{slug}', $route->getPath()); - $this->assertEquals('MyBlogBundle:Blog:show', $route->getDefault('_controller')); - $this->assertEquals('GET', $route->getRequirement('_method')); - $this->assertEquals('\w+', $route->getRequirement('locale')); - $this->assertEquals('{locale}.example.com', $route->getHost()); - $this->assertEquals('RouteCompiler', $route->getOption('compiler_class')); + + foreach ($routes as $route) { + $this->assertEquals('/blog/{slug}', $route->getPath()); + $this->assertEquals('MyBlogBundle:Blog:show', $route->getDefault('_controller')); + $this->assertEquals('GET', $route->getRequirement('_method')); + $this->assertEquals('https', $route->getRequirement('_scheme')); + $this->assertEquals('\w+', $route->getRequirement('locale')); + $this->assertEquals('{locale}.example.com', $route->getHost()); + $this->assertEquals('RouteCompiler', $route->getOption('compiler_class')); + } } public function testLoadWithResource() @@ -96,7 +99,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase $routeCollection = $loader->load('validresource.yml'); $routes = $routeCollection->all(); - $this->assertEquals(1, count($routes), 'One route is loaded'); + $this->assertCount(2, $routes, 'Two routes are loaded'); $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes); $this->assertEquals('/{foo}/blog/{slug}', $routes['blog_show']->getPath()); $this->assertEquals('MyBlogBundle:Blog:show', $routes['blog_show']->getDefault('_controller')); From 3615e199d24c7932fe9f62755b40e61cb92333db Mon Sep 17 00:00:00 2001 From: Adrien Samson Date: Thu, 7 Feb 2013 21:06:50 +0100 Subject: [PATCH 04/14] [Security] fixed session creation on login (closes #7011) --- .../Http/Firewall/ContextListener.php | 6 ++++-- .../Http/Firewall/ContextListenerTest.php | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php index b3f80b5f74..c24c879ef0 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php @@ -117,14 +117,16 @@ class ContextListener implements ListenerInterface } $request = $event->getRequest(); - $session = $request->hasPreviousSession() ? $request->getSession() : null; + $session = $request->getSession(); if (null === $session) { return; } if ((null === $token = $this->context->getToken()) || ($token instanceof AnonymousToken)) { - $session->remove('_security_'.$this->contextKey); + if ($request->hasPreviousSession()) { + $session->remove('_security_'.$this->contextKey); + } } else { $session->set('_security_'.$this->contextKey, serialize($token)); } diff --git a/src/Symfony/Component/Security/Tests/Http/Firewall/ContextListenerTest.php b/src/Symfony/Component/Security/Tests/Http/Firewall/ContextListenerTest.php index 2a8a28e942..ffe6195ff4 100644 --- a/src/Symfony/Component/Security/Tests/Http/Firewall/ContextListenerTest.php +++ b/src/Symfony/Component/Security/Tests/Http/Firewall/ContextListenerTest.php @@ -99,6 +99,25 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase $listener = new ContextListener($this->securityContext, array(), 'session'); $listener->onKernelResponse($event); + $this->assertTrue($session->isStarted()); + } + + public function testOnKernelResponseWithoutSessionNorToken() + { + $request = new Request(); + $session = new Session(new MockArraySessionStorage()); + $request->setSession($session); + + $event = new FilterResponseEvent( + $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'), + $request, + HttpKernelInterface::MASTER_REQUEST, + new Response() + ); + + $listener = new ContextListener($this->securityContext, array(), 'session'); + $listener->onKernelResponse($event); + $this->assertFalse($session->isStarted()); } From 83e95586e7d85b1de09b2bbb14f0788621bf2644 Mon Sep 17 00:00:00 2001 From: Ludek Stepan Date: Mon, 26 Nov 2012 15:59:46 +0100 Subject: [PATCH 05/14] Fix 'undefined index' error, when entering scope recursively --- .../DependencyInjection/Container.php | 6 ++-- .../Tests/ContainerTest.php | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index 1786158c0b..1a20e6f30e 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -334,8 +334,10 @@ class Container implements IntrospectableContainerInterface unset($this->scopedServices[$name]); foreach ($this->scopeChildren[$name] as $child) { - $services[$child] = $this->scopedServices[$child]; - unset($this->scopedServices[$child]); + if (isset($this->scopedServices[$child])) { + $services[$child] = $this->scopedServices[$child]; + unset($this->scopedServices[$child]); + } } // update global map diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php index 95b3953991..23c13c5094 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php @@ -261,6 +261,38 @@ class ContainerTest extends \PHPUnit_Framework_TestCase $this->assertFalse($container->has('a')); } + public function testEnterScopeRecursivelyWithInactiveChildScopes() + { + $container = new Container(); + $container->addScope(new Scope('foo')); + $container->addScope(new Scope('bar', 'foo')); + + $this->assertFalse($container->isScopeActive('foo')); + + $container->enterScope('foo'); + + $this->assertTrue($container->isScopeActive('foo')); + $this->assertFalse($container->isScopeActive('bar')); + $this->assertFalse($container->has('a')); + + $a = new \stdClass(); + $container->set('a', $a, 'foo'); + + $services = $this->getField($container, 'scopedServices'); + $this->assertTrue(isset($services['foo']['a'])); + $this->assertSame($a, $services['foo']['a']); + + $this->assertTrue($container->has('a')); + $container->enterScope('foo'); + + $services = $this->getField($container, 'scopedServices'); + $this->assertFalse(isset($services['a'])); + + $this->assertTrue($container->isScopeActive('foo')); + $this->assertFalse($container->isScopeActive('bar')); + $this->assertFalse($container->has('a')); + } + public function testLeaveScopeNotActive() { $container = new Container(); From bd0ad9255908c0880cd51e01b9be2c430c6ca84e Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 7 Feb 2013 19:50:13 +0100 Subject: [PATCH 06/14] [DependencyInjection] Allow frozen containers to be dumped to graphviz --- .../Dumper/GraphvizDumper.php | 24 +++++++++++++++++-- .../Tests/Fixtures/containers/container13.php | 13 ++++++++++ .../Tests/Fixtures/containers/container14.php | 11 +++++++++ .../Tests/Fixtures/graphviz/services13.dot | 8 +++++++ .../Tests/Fixtures/graphviz/services14.dot | 7 ++++++ .../Dumper/GraphvizDumperTest.php | 14 +++++++++++ 6 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container13.php create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container14.php create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services13.dot create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services14.dot diff --git a/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php index debdc52709..61320f996f 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php @@ -15,6 +15,8 @@ use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Parameter; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; /** * GraphvizDumper dumps a service container as a graphviz file. @@ -159,7 +161,7 @@ class GraphvizDumper extends Dumper { $nodes = array(); - $container = clone $this->container; + $container = $this->cloneContainer(); foreach ($container->getDefinitions() as $id => $definition) { $nodes[$id] = array('class' => str_replace('\\', '\\\\', $this->container->getParameterBag()->resolveValue($definition->getClass())), 'attributes' => array_merge($this->options['node.definition'], array('style' => ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope() ? 'filled' : 'dotted'))); @@ -175,13 +177,31 @@ class GraphvizDumper extends Dumper } if (!$container->hasDefinition($id)) { - $nodes[$id] = array('class' => str_replace('\\', '\\\\', get_class($service)), 'attributes' => $this->options['node.instance']); + $class = ('service_container' === $id) ? get_class($this->container) : get_class($service); + $nodes[$id] = array('class' => str_replace('\\', '\\\\', $class), 'attributes' => $this->options['node.instance']); } } return $nodes; } + private function cloneContainer() + { + $parameterBag = new ParameterBag($this->container->getParameterBag()->all()); + + $container = new ContainerBuilder($parameterBag); + $container->setDefinitions($this->container->getDefinitions()); + $container->setAliases($this->container->getAliases()); + foreach ($this->container->getScopes() as $scope) { + $container->addScope($scope); + } + foreach ($this->container->getExtensions() as $extension) { + $container->registerExtension($extension); + } + + return $container; + } + /** * Returns the start dot. * diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container13.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container13.php new file mode 100644 index 0000000000..17b32cf512 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container13.php @@ -0,0 +1,13 @@ + + register('foo', 'FooClass')-> + addArgument(new Reference('bar')) +; +$container->compile(); + +return $container; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container14.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container14.php new file mode 100644 index 0000000000..593be9c399 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container14.php @@ -0,0 +1,11 @@ + array('fillcolor' => 'red', 'style' => 'empty'), )), str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services10-1.dot')), '->dump() dumps services'); } + + public function testDumpWithFrozenContainer() + { + $container = include self::$fixturesPath.'/containers/container13.php'; + $dumper = new GraphvizDumper($container); + $this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services13.dot')), $dumper->dump(), '->dump() dumps services'); + } + + public function testDumpWithFrozenCustomClassContainer() + { + $container = include self::$fixturesPath.'/containers/container14.php'; + $dumper = new GraphvizDumper($container); + $this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services14.dot')), $dumper->dump(), '->dump() dumps services'); + } } From e0637fa9b75e9a74e6a23dd0167cf74ee9518403 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 7 Feb 2013 23:37:22 +0100 Subject: [PATCH 07/14] [DependencyInjection] Add clone for resources which were introduced in 2.1 --- .../Component/DependencyInjection/Dumper/GraphvizDumper.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php index 61320f996f..c07f275a2b 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php @@ -192,6 +192,7 @@ class GraphvizDumper extends Dumper $container = new ContainerBuilder($parameterBag); $container->setDefinitions($this->container->getDefinitions()); $container->setAliases($this->container->getAliases()); + $container->setResources($this->container->getResources()); foreach ($this->container->getScopes() as $scope) { $container->addScope($scope); } From 87f3db780e9a381565593be596b03bb3d96e6ca6 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 8 Feb 2013 14:08:13 +0100 Subject: [PATCH 08/14] [EventDispathcer] Fix removeListener --- .../EventDispatcher/EventDispatcher.php | 2 +- .../EventDispatcher/EventDispatcherTest.php | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/EventDispatcher/EventDispatcher.php b/src/Symfony/Component/EventDispatcher/EventDispatcher.php index f6e4d0a070..f2d35c5074 100644 --- a/src/Symfony/Component/EventDispatcher/EventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/EventDispatcher.php @@ -100,7 +100,7 @@ class EventDispatcher implements EventDispatcherInterface } foreach ($this->listeners[$eventName] as $priority => $listeners) { - if (false !== ($key = array_search($listener, $listeners))) { + if (false !== ($key = array_search($listener, $listeners, true))) { unset($this->listeners[$eventName][$priority][$key], $this->sorted[$eventName]); } } diff --git a/tests/Symfony/Tests/Component/EventDispatcher/EventDispatcherTest.php b/tests/Symfony/Tests/Component/EventDispatcher/EventDispatcherTest.php index 62cd9e5193..7311c6bc8f 100644 --- a/tests/Symfony/Tests/Component/EventDispatcher/EventDispatcherTest.php +++ b/tests/Symfony/Tests/Component/EventDispatcher/EventDispatcherTest.php @@ -207,6 +207,28 @@ class EventDispatcherTest extends \PHPUnit_Framework_TestCase $this->dispatcher->removeSubscriber($eventSubscriber); $this->assertFalse($this->dispatcher->hasListeners(self::preFoo)); } + + /** + * @see https://bugs.php.net/bug.php?id=62976 + * + * This bug affects: + * - The PHP 5.3 branch for versions < 5.3.18 + * - The PHP 5.4 branch for versions < 5.4.8 + * - The PHP 5.5 branch is not affected + */ + public function testWorkaroundForPhpBug62976() + { + $dispatcher = new EventDispatcher(); + $dispatcher->addListener('bug.62976', new CallableClass()); + $dispatcher->removeListener('bug.62976', function() {}); + } +} + +class CallableClass +{ + public function __invoke() + { + } } class TestEventListener From 4ce9ac3a279143ce9aa8bf2a33076ff271593cdf Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Sun, 10 Feb 2013 12:26:00 +0100 Subject: [PATCH 09/14] [EventDispatcher] Added assertion. --- .../Tests/Component/EventDispatcher/EventDispatcherTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Symfony/Tests/Component/EventDispatcher/EventDispatcherTest.php b/tests/Symfony/Tests/Component/EventDispatcher/EventDispatcherTest.php index 7311c6bc8f..0ffde515c9 100644 --- a/tests/Symfony/Tests/Component/EventDispatcher/EventDispatcherTest.php +++ b/tests/Symfony/Tests/Component/EventDispatcher/EventDispatcherTest.php @@ -221,6 +221,7 @@ class EventDispatcherTest extends \PHPUnit_Framework_TestCase $dispatcher = new EventDispatcher(); $dispatcher->addListener('bug.62976', new CallableClass()); $dispatcher->removeListener('bug.62976', function() {}); + $this->assertTrue($dispatcher->hasListeners('bug.62976')); } } From 6a9c5102b29851460aafbcdae44d09ed7b002571 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 9 Feb 2013 21:11:02 +0100 Subject: [PATCH 10/14] fixed the IP address in HttpCache when calling the backend --- src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php | 4 ++++ .../HttpKernel/Tests/HttpCache/HttpCacheTest.php | 8 ++++++++ .../HttpKernel/Tests/HttpCache/TestHttpKernel.php | 7 +++++++ .../HttpKernel/Tests/HttpCache/TestMultipleHttpKernel.php | 8 ++++++++ 4 files changed, 27 insertions(+) diff --git a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php index ec66dcd5fc..1bc3aa492e 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php @@ -413,6 +413,10 @@ class HttpCache implements HttpKernelInterface, TerminableInterface $subRequest->headers->remove('if_modified_since'); $subRequest->headers->remove('if_none_match'); + // 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')) { diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php index 5060a696c2..31dbbd555c 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php @@ -1034,4 +1034,12 @@ class HttpCacheTest extends HttpCacheTestCase $this->assertEquals('Hello World!', $this->response->getContent()); $this->assertEquals(12, $this->response->headers->get('Content-Length')); } + + public function testClientIpIsAlwaysLocalhostForForwardedRequests() + { + $this->setNextResponse(); + $this->request('GET', '/', array('REMOTE_ADDR' => '10.0.0.1')); + + $this->assertEquals('127.0.0.1', $this->kernel->getBackendRequest()->server->get('REMOTE_ADDR')); + } } diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpCache/TestHttpKernel.php b/src/Symfony/Component/HttpKernel/Tests/HttpCache/TestHttpKernel.php index c732c673f3..cf23d7bf8a 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpCache/TestHttpKernel.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpCache/TestHttpKernel.php @@ -26,6 +26,7 @@ class TestHttpKernel extends HttpKernel implements ControllerResolverInterface protected $called; protected $customizer; protected $catch; + protected $backendRequest; public function __construct($body, $status, $headers, \Closure $customizer = null) { @@ -39,9 +40,15 @@ class TestHttpKernel extends HttpKernel implements ControllerResolverInterface parent::__construct(new EventDispatcher(), $this); } + public function getBackendRequest() + { + return $this->backendRequest; + } + public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false) { $this->catch = $catch; + $this->backendRequest = $request; return parent::handle($request, $type, $catch); } diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpCache/TestMultipleHttpKernel.php b/src/Symfony/Component/HttpKernel/Tests/HttpCache/TestMultipleHttpKernel.php index eeb9bea0dc..6dd3d9e499 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpCache/TestMultipleHttpKernel.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpCache/TestMultipleHttpKernel.php @@ -25,6 +25,7 @@ class TestMultipleHttpKernel extends HttpKernel implements ControllerResolverInt protected $headers; protected $catch; protected $call; + protected $backendRequest; public function __construct($responses) { @@ -42,8 +43,15 @@ class TestMultipleHttpKernel extends HttpKernel implements ControllerResolverInt parent::__construct(new EventDispatcher(), $this); } + public function getBackendRequest() + { + return $this->backendRequest; + } + public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false) { + $this->backendRequest = $request; + return parent::handle($request, $type, $catch); } From 42d3c4c9cab5ec7ebcc17ffd41a12b99156147c6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 9 Feb 2013 21:11:21 +0100 Subject: [PATCH 11/14] added support for the X-Forwarded-For header (closes #6982, closes #7000) --- .../HttpKernel/HttpCache/HttpCache.php | 8 +++++++ .../Tests/HttpCache/HttpCacheTest.php | 24 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php index 1bc3aa492e..97e365008b 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php @@ -413,6 +413,14 @@ 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'); diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php index 31dbbd555c..89203a8ae2 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php @@ -1042,4 +1042,28 @@ class HttpCacheTest extends HttpCacheTestCase $this->assertEquals('127.0.0.1', $this->kernel->getBackendRequest()->server->get('REMOTE_ADDR')); } + + /** + * @dataProvider getXForwardedForData + */ + public function testXForwarderForHeaderForForwardedRequests($xForwardedFor, $expected) + { + $this->setNextResponse(); + $server = array('REMOTE_ADDR' => '10.0.0.1'); + if (false !== $xForwardedFor) { + $server['HTTP_X_FORWARDED_FOR'] = $xForwardedFor; + } + $this->request('GET', '/', $server); + + $this->assertEquals($expected, $this->kernel->getBackendRequest()->headers->get('X-Forwarded-For')); + } + + public function getXForwardedForData() + { + return array( + array(false, '10.0.0.1'), + array('10.0.0.2', '10.0.0.2, 10.0.0.1'), + array('10.0.0.2, 10.0.0.3', '10.0.0.2, 10.0.0.3, 10.0.0.1'), + ); + } } From 4cbdbcb1f95c3459fbf1baa84f798cab68a8a9d6 Mon Sep 17 00:00:00 2001 From: Florin Patan Date: Tue, 5 Feb 2013 12:07:10 +0200 Subject: [PATCH 12/14] [Validator] Add check for existing metadata on property --- .../Component/Validator/Mapping/ClassMetadata.php | 8 ++++++++ .../Validator/PropertyMetadataContainerInterface.php | 9 +++++++++ src/Symfony/Component/Validator/Tests/ValidatorTest.php | 4 ++++ src/Symfony/Component/Validator/Validator.php | 8 ++++++++ 4 files changed, 29 insertions(+) diff --git a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php index 8ce479b3dd..6ea9f2f6d9 100644 --- a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php +++ b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php @@ -301,6 +301,14 @@ class ClassMetadata extends ElementMetadata implements MetadataInterface, ClassB return $this->members[$property]; } + /** + * {@inheritdoc} + */ + public function hasPropertyMetadata($property) + { + return array_key_exists($property, $this->members); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/Validator/PropertyMetadataContainerInterface.php b/src/Symfony/Component/Validator/PropertyMetadataContainerInterface.php index 33db49e4e1..20bafb2950 100644 --- a/src/Symfony/Component/Validator/PropertyMetadataContainerInterface.php +++ b/src/Symfony/Component/Validator/PropertyMetadataContainerInterface.php @@ -18,6 +18,15 @@ namespace Symfony\Component\Validator; */ interface PropertyMetadataContainerInterface { + /** + * Check if there's any metadata attached to the given named property. + * + * @param string $property The property name. + * + * @return Boolean + */ + public function hasPropertyMetadata($property); + /** * Returns all metadata instances for the given named property. * diff --git a/src/Symfony/Component/Validator/Tests/ValidatorTest.php b/src/Symfony/Component/Validator/Tests/ValidatorTest.php index 502671fd8e..dbfa4f298d 100644 --- a/src/Symfony/Component/Validator/Tests/ValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/ValidatorTest.php @@ -187,6 +187,10 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase $result = $this->validator->validateProperty($entity, 'firstName'); $this->assertCount(1, $result); + + $result = $this->validator->validateProperty($entity, 'lastName'); + + $this->assertCount(0, $result); } public function testValidatePropertyValue() diff --git a/src/Symfony/Component/Validator/Validator.php b/src/Symfony/Component/Validator/Validator.php index a700692d8d..8221d60266 100644 --- a/src/Symfony/Component/Validator/Validator.php +++ b/src/Symfony/Component/Validator/Validator.php @@ -112,6 +112,10 @@ class Validator implements ValidatorInterface } foreach ($this->resolveGroups($groups) as $group) { + if (!$metadata->hasPropertyMetadata($property)) { + continue; + } + foreach ($metadata->getPropertyMetadata($property) as $propMeta) { $propMeta->accept($visitor, $propMeta->getPropertyValue($containingValue), $group, $property); } @@ -139,6 +143,10 @@ class Validator implements ValidatorInterface } foreach ($this->resolveGroups($groups) as $group) { + if (!$metadata->hasPropertyMetadata($property)) { + continue; + } + foreach ($metadata->getPropertyMetadata($property) as $propMeta) { $propMeta->accept($visitor, $value, $group, $property); } From a9238493a705063db5b4be3eb7e110e87474ff70 Mon Sep 17 00:00:00 2001 From: povilas Date: Fri, 11 Jan 2013 17:40:42 +0200 Subject: [PATCH 13/14] moved file hash calculation to own method --- .../HttpFoundation/BinaryFileResponse.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php index cb6c8a1e8a..9f5bb21971 100644 --- a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php +++ b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php @@ -22,6 +22,7 @@ use Symfony\Component\HttpFoundation\File\Exception\FileException; * @author Igor Wiedler * @author Jordan Alliot * @author Sergey Linnik + * @author Povilas Skruibis */ class BinaryFileResponse extends Response { @@ -123,11 +124,23 @@ class BinaryFileResponse extends Response */ public function setAutoEtag() { - $this->setEtag(sha1_file($this->file->getPathname())); + $this->setEtag($this->calculateFileHash($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 f0afc2c0096c7b7d63bfee19341a825a040472ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Mon, 17 Dec 2012 10:00:47 +0100 Subject: [PATCH 14/14] Fixed XmlFileLoaderTest::testLoadThrowsExceptionWithInvalidFileEvenWithoutSchemaValidation --- .../Component/Routing/Tests/Fixtures/CustomXmlFileLoader.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/CustomXmlFileLoader.php b/src/Symfony/Component/Routing/Tests/Fixtures/CustomXmlFileLoader.php index c2601d4581..12a5bedb4f 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/CustomXmlFileLoader.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/CustomXmlFileLoader.php @@ -12,14 +12,15 @@ namespace Symfony\Component\Routing\Tests\Fixtures; use Symfony\Component\Routing\Loader\XmlFileLoader; +use Symfony\Component\Config\Util\XmlUtils; /** * XmlFileLoader with schema validation turned off */ class CustomXmlFileLoader extends XmlFileLoader { - protected function validate(\DOMDocument $dom) + protected function loadFile($file) { - return true; + return XmlUtils::loadFile($file, function() { return true; }); } }