10000 [Filesystem] Fixed relative path calculation for paths with various c… · gbenoit79/symfony@bc93787 · GitHub
[go: up one dir, main page]

Skip to content

Commit bc93787

Browse files
committed
[Filesystem] Fixed relative path calculation for paths with various combinations of trailing directory separators.
1 parent dee79e9 commit bc93787

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ public function makePathRelative($endPath, $startPath)
185185
}
186186

187187
// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
188-
$depth = substr_count(substr($startPath, $offset), DIRECTORY_SEPARATOR) + 1;
188+
$diffPath = trim(substr($startPath, $offset), DIRECTORY_SEPARATOR);
189+
$depth = substr_count($diffPath, DIRECTORY_SEPARATOR) + 1;
189190

190191
// Repeated "../" for each level need to reach the common path
191192
$traverser = str_repeat('../', $depth);

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,9 @@ public function providePathsForMakePathRelative()
443443
{
444444
$paths = array(
445445
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/src/Symfony/Component', '../'),
446+
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/src/Symfony/Component/', '../'),
447+
array('/var/lib/symfony/src/Symfony', '/var/lib/symfony/src/Symfony/Component', '../'),
448+
array('/var/lib/symfony/src/Symfony', '/var/lib/symfony/src/Symfony/Component/', '../'),
446449
array('var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component', '../../../'),
447450
array('/usr/lib/symfony/', '/var/lib/symfony/src/Symfony/Component', '../../../../../../usr/lib/symfony/'),
448451
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/', '../src/Symfony/'),

0 commit comments

Comments
 (0)
0