[Filesystem] Fixed relative path calculation for paths with various combinations of trailing directory separators.

This commit is contained in:
Jakub Zalas 2012-04-07 21:19:12 +01:00
parent dee79e910d
commit bc93787a0d
2 changed files with 5 additions and 1 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 = substr_count($diffPath, DIRECTORY_SEPARATOR) + 1;
// Repeated "../" for each level need to reach the common path
$traverser = str_repeat('../', $depth);

View File

@ -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/'),