From d50ffa1de7e0474024147b68b69db9b036d5b70d Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 21 Mar 2017 09:40:59 +0100 Subject: [PATCH 1/4] normalize paths before making them relative --- .../Component/Filesystem/Filesystem.php | 25 +++++++++++++++++++ .../Filesystem/Tests/FilesystemTest.php | 10 ++++++++ 2 files changed, 35 insertions(+) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 3a5e332b9e..edfc1b9d46 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -362,6 +362,31 @@ class Filesystem $startPathArr = explode('/', trim($startPath, '/')); $endPathArr = explode('/', trim($endPath, '/')); + if ('/' !== $startPath[0]) { + array_shift($startPathArr); + } + + if ('/' !== $endPath[0]) { + array_shift($endPathArr); + } + + $normalizePathArray = function ($pathSegments) { + $result = array(); + + foreach ($pathSegments as $segment) { + if ('..' === $segment) { + array_pop($result); + } else { + $result[] = $segment; + } + } + + return $result; + }; + + $startPathArr = $normalizePathArray($startPathArr); + $endPathArr = $normalizePathArray($endPathArr); + // Find for which directory the common path stops $index = 0; while (isset($startPathArr[$index]) && isset($endPathArr[$index]) && $startPathArr[$index] === $endPathArr[$index]) { diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index be47a2d0ce..ab2395cd00 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -868,6 +868,16 @@ class FilesystemTest extends FilesystemTestCase array('/a/aab/bb/', '/b/aab', '../../a/aab/bb/'), array('/aab/bb', '/aa', '../aab/bb/'), array('/aab', '/aa', '../aab/'), + array('/aa/bb/cc', '/aa/dd/..', 'bb/cc/'), + array('/aa/../bb/cc', '/aa/dd/..', '../bb/cc/'), + array('/aa/bb/../../cc', '/aa/../dd/..', 'cc/'), + array('/../aa/bb/cc', '/aa/dd/..', 'bb/cc/'), + array('/../../aa/../bb/cc', '/aa/dd/..', '../bb/cc/'), + array('C:/aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'), + array('c:/aa/../bb/cc', 'c:/aa/dd/..', '../bb/cc/'), + array('C:/aa/bb/../../cc', 'C:/aa/../dd/..', 'cc/'), + array('C:/../aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'), + array('C:/../../aa/../bb/cc', 'C:/aa/dd/..', '../bb/cc/'), ); if ('\\' === DIRECTORY_SEPARATOR) { From 967f7a7add84628ac3301a892e920b32aa3488bd Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Fri, 24 Mar 2017 04:23:13 +0100 Subject: [PATCH 2/4] MockArraySessionStorage: updated phpdoc for $bags so that IDE autocompletion would work --- .../HttpFoundation/Session/Storage/MockArraySessionStorage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php index c26cc1334d..c932d4003f 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php @@ -58,7 +58,7 @@ class MockArraySessionStorage implements SessionStorageInterface protected $metadataBag; /** - * @var array + * @var array|SessionBagInterface[] */ protected $bags; From d984c73e66ec5bd5ecfe46d62e5f0d9fd732a179 Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Fri, 24 Mar 2017 04:07:57 +0100 Subject: [PATCH 3/4] [HttpFoundation][bugfix] should always be initialized --- .../Storage/MockArraySessionStorage.php | 2 +- .../Storage/MockArraySessionStorageTest.php | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php index c26cc1334d..78404d7b44 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php @@ -60,7 +60,7 @@ class MockArraySessionStorage implements SessionStorageInterface /** * @var array */ - protected $bags; + protected $bags = array(); /** * Constructor. diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php index 99da778b5f..82df5543eb 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php @@ -97,6 +97,30 @@ class MockArraySessionStorageTest extends TestCase $this->assertNotEquals('', $this->storage->getId()); } + public function testClearClearsBags() + { + $this->storage->clear(); + + $this->assertSame(array(), $this->storage->getBag('attributes')->all()); + $this->assertSame(array(), $this->storage->getBag('flashes')->peekAll()); + } + + public function testClearStartsSession() + { + $this->storage->clear(); + + $this->assertTrue($this->storage->isStarted()); + } + + public function testClearWithNoBagsStartsSession() + { + $storage = new MockArraySessionStorage(); + + $storage->clear(); + + $this->assertTrue($storage->isStarted()); + } + /** * @expectedException \RuntimeException */ From 0577c7b089916bde9243fee8cfd08fc14fad1eac Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 26 Mar 2017 17:08:59 +0200 Subject: [PATCH 4/4] [Bridge\Doctrine] Fix change breaking doctrine-bundle test suite --- ...egisterEventListenersAndSubscribersPass.php | 7 ++----- ...terEventListenersAndSubscribersPassTest.php | 18 +++++++++--------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php b/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php index 1ec3ba323b..cb4a4816db 100644 --- a/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php +++ b/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php @@ -109,15 +109,12 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface throw new RuntimeException(sprintf('The Doctrine connection "%s" referenced in service "%s" does not exist. Available connections names: %s', $con, $id, implode(', ', array_keys($this->connections)))); } - if ($lazy = isset($tag['lazy']) && $tag['lazy']) { + if ($lazy = !empty($tag['lazy'])) { $taggedListenerDef->setPublic(true); } // we add one call per event per service so we have the correct order - $this->getEventManagerDef($container, $con)->addMethodCall('addEventListener', array( - $tag['event'], - $lazy ? $id : new Reference($id), - )); + $this->getEventManagerDef($container, $con)->addMethodCall('addEventListener', array(array($tag['event']), $lazy ? $id : new Reference($id))); } } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPassTest.php b/src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPassTest.php index 6e4eb20298..7e99a7d935 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPassTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPassTest.php @@ -90,11 +90,11 @@ class RegisterEventListenersAndSubscribersPassTest extends TestCase $this->assertEquals( array( - array('addEventListener', array('foo_bar', new Reference('c'))), - array('addEventListener', array('foo_bar', new Reference('a'))), - array('addEventListener', array('bar', new Reference('a'))), - array('addEventListener', array('foo', new Reference('b'))), - array('addEventListener', array('foo', new Reference('a'))), + array('addEventListener', array(array('foo_bar'), new Reference('c'))), + array('addEventListener', array(array('foo_bar'), new Reference('a'))), + array('addEventListener', array(array('bar'), new Reference('a'))), + array('addEventListener', array(array('foo'), new Reference('b'))), + array('addEventListener', array(array('foo'), new Reference('a'))), ), $methodCalls ); @@ -138,16 +138,16 @@ class RegisterEventListenersAndSubscribersPassTest extends TestCase $this->assertEquals( array( - array('addEventListener', array('onFlush', new Reference('a'))), - array('addEventListener', array('onFlush', new Reference('b'))), + array('addEventListener', array(array('onFlush'), new Reference('a'))), + array('addEventListener', array(array('onFlush'), new Reference('b'))), ), $container->getDefinition('doctrine.dbal.default_connection.event_manager')->getMethodCalls() ); $this->assertEquals( array( - array('addEventListener', array('onFlush', new Reference('a'))), - array('addEventListener', array('onFlush', new Reference('c'))), + array('addEventListener', array(array('onFlush'), new Reference('a'))), + array('addEventListener', array(array('onFlush'), new Reference('c'))), ), $container->getDefinition('doctrine.dbal.second_connection.event_manager')->getMethodCalls() );