From 22e2ad80c90f4bacbc2ebf4c8ea0d089ac57bc58 Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Sat, 7 Apr 2012 21:52:26 +0100 Subject: [PATCH] [Filesystem] Fixed relative path calculation for end path which is a subdirectory of the start path. --- src/Symfony/Component/Filesystem/Filesystem.php | 2 +- src/Symfony/Component/Filesystem/Tests/FilesystemTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index c0fe4b48d7..a63c5a313f 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -186,7 +186,7 @@ class Filesystem // Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels) $diffPath = trim(substr($startPath, $offset), DIRECTORY_SEPARATOR); - $depth = substr_count($diffPath, DIRECTORY_SEPARATOR) + 1; + $depth = strlen($diffPath) > 0 ? substr_count($diffPath, DIRECTORY_SEPARATOR) + 1 : 0; // 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 faa189c971..80b5167231 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -448,7 +448,7 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase 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/'), + array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/', 'src/Symfony/'), ); // fix directory separator