diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index b99b65162e..c0fe4b48d7 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -185,7 +185,8 @@ class Filesystem } // Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels) - $depth = substr_count(substr($startPath, $offset), DIRECTORY_SEPARATOR) + 1; + $diffPath = trim(substr($startPath, $offset), DIRECTORY_SEPARATOR); + $depth = substr_count($diffPath, DIRECTORY_SEPARATOR) + 1; // Repeated "../" for each level need to reach the common path $traverser = str_repeat('../', $depth); diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index b6c48fab6f..faa189c971 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -443,6 +443,9 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase { $paths = array( array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/src/Symfony/Component', '../'), + array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/src/Symfony/Component/', '../'), + array('/var/lib/symfony/src/Symfony', '/var/lib/symfony/src/Symfony/Component', '../'), + array('/var/lib/symfony/src/Symfony', '/var/lib/symfony/src/Symfony/Component/', '../'), array('var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component', '../../../'), array('/usr/lib/symfony/', '/var/lib/symfony/src/Symfony/Component', '../../../../../../usr/lib/symfony/'), array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/', '../src/Symfony/'),