merged branch jakzal/FilesystemBugFix (PR #3828)

Commits
-------

22e2ad8 [Filesystem] Fixed relative path calculation for end path which is a subdirectory of the start path.
bc93787 [Filesystem] Fixed relative path calculation for paths with various combinations of trailing directory separators.

Discussion
----------

[Filesystem] Fixed relative path calculation

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
This commit is contained in:
Fabien Potencier 2012-04-08 09:16:07 +02:00
commit bca8c5feac
2 changed files with 6 additions and 2 deletions

View File

@ -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 = strlen($diffPath) > 0 ? substr_count($diffPath, DIRECTORY_SEPARATOR) + 1 : 0;
// Repeated "../" for each level need to reach the common path
$traverser = str_repeat('../', $depth);

View File

@ -443,9 +443,12 @@ 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/'),
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/', 'src/Symfony/'),
);
// fix directory separator