Skip to content

Commit

Permalink
bug #19478 fixed Filesystem:makePathRelative and added 2 more testcas…
Browse files Browse the repository at this point in the history
…es (muhammedeminakbulut)

This PR was submitted for the 2.8 branch but it was merged into the 2.7 branch instead (closes #19478).

Discussion
----------

fixed Filesystem:makePathRelative and added 2 more testcases

| Q             | A
| ------------- | ---
| Branch?       |2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT
The 2 new test cases where broken on the old code. The old testcases and the new one succeed with the given code.

Commits
-------

cd3206c fixed Filesystem:makePathRelative and added 2 more testcases
  • Loading branch information
fabpot committed Oct 14, 2016
2 parents 8d218e7 + cd3206c commit 287713f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Symfony/Component/Filesystem/Filesystem.php
Expand Up @@ -369,10 +369,14 @@ public function makePathRelative($endPath, $startPath)
}

// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
$depth = count($startPathArr) - $index;
if (count($startPathArr) === 1 && $startPathArr[0] === '') {
$depth = 0;
} else {
$depth = count($startPathArr) - $index;
}

// When we need to traverse from the start, and we are starting from a root path, don't add '../'
if ('/' === $startPath[0] && 0 === $index && 1 === $depth) {
if ('/' === $startPath[0] && 0 === $index && 0 === $depth) {
$traverser = '';
} else {
// Repeated "../" for each level need to reach the common path
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Expand Up @@ -840,6 +840,8 @@ public function providePathsForMakePathRelative()
array('/a/aab/bb/', '/a/aa/', '../aab/bb/'),
array('/a/aab/bb/', '/', 'a/aab/bb/'),
array('/a/aab/bb/', '/b/aab', '../../a/aab/bb/'),
array('/aab/bb', '/aa', '../aab/bb/'),
array('/aab', '/aa', '../aab/'),
);

if ('\\' === DIRECTORY_SEPARATOR) {
Expand Down

0 comments on commit 287713f

Please sign in to comment.