Skip to content

Commit

Permalink
merged branch jakzal/FilesystemBugFix (PR symfony#3828)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fabpot committed Apr 8, 2012
2 parents dee79e9 + 22e2ad8 commit bca8c5f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ public function makePathRelative($endPath, $startPath)
}

// 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);
Expand Down
5 changes: 4 additions & 1 deletion src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,12 @@ public function providePathsForMakePathRelative()
{
$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
Expand Down

0 comments on commit bca8c5f

Please sign in to comment.