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:
commit
bca8c5feac
@ -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);
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user