8000 Do not strip ../ segments from the beginning of relative paths · symfony/symfony@9586e88 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9586e88

Browse files
committed
Do not strip ../ segments from the beginning of relative paths
1 parent 15982d4 commit 9586e88

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,12 @@ public function makePathRelative($endPath, $startPath)
372372
$startPathArr = explode('/', trim($startPath, '/'));
373373
$endPathArr = explode('/', trim($endPath, '/'));
374374

375-
$normalizePathArray = function ($pathSegments) {
375+
$normalizePathArray = function ($pathSegments, $path) {
376+
$absolute = static::isAbsolutePath($path);
376377
$result = array();
377378

3783 8000 79
foreach ($pathSegments as $segment) {
379-
if ('..' === $segment) {
380+
if ('..' === $segment && ($absolute || count($result))) {
380381
array_pop($result);
381382
} elseif ('.' !== $segment) {
382383
$result[] = $segment;
@@ -386,8 +387,8 @@ public function makePathRelative($endPath, $startPath)
386387
return $result;
387388
};
388389

389-
$startPathArr = $normalizePathArray($startPathArr);
390-
$endPathArr = $normalizePathArray($endPathArr);
390+
$startPathArr = $normalizePathArray($startPathArr, $startPath);
391+
$endPathArr = $normalizePathArray($endPathArr, $endPath);
391392

392393
// Find for which directory the common path stops
393394
$index = 0;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,12 @@ public function providePathsForMakePathRelative()
884884
array('aa/bb', 'aa/./cc', '../bb/'),
885885
array('aa/./bb', 'aa/cc', '../bb/'),
886886
array('aa/./bb', 'aa/./cc', '../bb/'),
887+
array('../../', '../../', './'),
888+
array('../aa/bb/', 'aa/bb/', '../../../aa/bb/'),
889+
array('../../../', '../../', '../'),
890+
array('', '', './'),
891+
array('', 'aa/', '../'),
892+
array('aa/', '', 'aa/'),
887893
);
888894

889895
if ('\\' === DIRECTORY_SEPARATOR) {

0 commit comments

Comments
 (0)
0