From 75c649a204ca25060df052b4671090c41de1aaf2 Mon Sep 17 00:00:00 2001 From: Csaba Maulis Date: Mon, 1 Feb 2021 12:34:37 +0800 Subject: [PATCH 1/2] Fix Filesystem::makePathRelative when end path does not end with a slash --- .../Component/Filesystem/Filesystem.php | 5 ++- .../Filesystem/Tests/FilesystemTest.php | 38 +++++++++---------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 4053d9e6a5e8..5fdf2d470efa 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -479,10 +479,11 @@ public function makePathRelative($endPath, $startPath) $startPathArr = $splitPath($startPath); $endPathArr = $splitPath($endPath); + $pathEnd = str_ends_with($endPath, '/') ? '/' : ''; if ($endDriveLetter && $startDriveLetter && $endDriveLetter != $startDriveLetter) { // End path is on another drive, so no relative path exists - return $endDriveLetter.':/'.($endPathArr ? implode('/', $endPathArr).'/' : ''); + return $endDriveLetter.':/'.($endPathArr ? implode('/', $endPathArr).$pathEnd : ''); } // Find for which directory the common path stops @@ -504,7 +505,7 @@ public function makePathRelative($endPath, $startPath) $endPathRemainder = implode('/', \array_slice($endPathArr, $index)); // Construct $endPath from traversing to the common path, then to the remaining $endPath - $relativePath = $traverser.('' !== $endPathRemainder ? $endPathRemainder.'/' : ''); + $relativePath = $traverser.('' !== $endPathRemainder ? $endPathRemainder.$pathEnd : ''); return '' === $relativePath ? './' : $relativePath; } diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index c5f1674c4e37..7250c6ac7ee2 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -1114,32 +1114,32 @@ public function providePathsForMakePathRelative() ['/aa/bb/cc', '/aa/bb/cc/dd/', '../'], ['/aa/bb/cc/', '/aa/bb/cc/dd', '../'], ['/aa/bb/cc/', '/aa/bb/cc/dd/', '../'], - ['/aa/bb/cc', '/aa', 'bb/cc/'], - ['/aa/bb/cc', '/aa/', 'bb/cc/'], + ['/aa/bb/cc', '/aa', 'bb/cc'], + ['/aa/bb/cc', '/aa/', 'bb/cc'], ['/aa/bb/cc/', '/aa', 'bb/cc/'], ['/aa/bb/cc/', '/aa/', 'bb/cc/'], - ['/a/aab/bb', '/a/aa', '../aab/bb/'], - ['/a/aab/bb', '/a/aa/', '../aab/bb/'], + ['/a/aab/bb', '/a/aa', '../aab/bb'], + ['/a/aab/bb', '/a/aa/', '../aab/bb'], ['/a/aab/bb/', '/a/aa', '../aab/bb/'], ['/a/aab/bb/', '/a/aa/', '../aab/bb/'], ['/a/aab/bb/', '/', 'a/aab/bb/'], ['/a/aab/bb/', '/b/aab', '../../a/aab/bb/'], - ['/aab/bb', '/aa', '../aab/bb/'], - ['/aab', '/aa', '../aab/'], - ['/aa/bb/cc', '/aa/dd/..', 'bb/cc/'], - ['/aa/../bb/cc', '/aa/dd/..', '../bb/cc/'], - ['/aa/bb/../../cc', '/aa/../dd/..', 'cc/'], - ['/../aa/bb/cc', '/aa/dd/..', 'bb/cc/'], - ['/../../aa/../bb/cc', '/aa/dd/..', '../bb/cc/'], - ['C:/aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'], - ['C:/aa/bb/cc', 'c:/aa/dd/..', 'bb/cc/'], - ['c:/aa/../bb/cc', 'c:/aa/dd/..', '../bb/cc/'], - ['C:/aa/bb/../../cc', 'C:/aa/../dd/..', 'cc/'], - ['C:/../aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'], - ['C:/../../aa/../bb/cc', 'C:/aa/dd/..', '../bb/cc/'], + ['/aab/bb', '/aa', '../aab/bb'], + ['/aab', '/aa', '../aab'], + ['/aa/bb/cc', '/aa/dd/..', 'bb/cc'], + ['/aa/../bb/cc', '/aa/dd/..', '../bb/cc'], + ['/aa/bb/../../cc', '/aa/../dd/..', 'cc'], + ['/../aa/bb/cc', '/aa/dd/..', 'bb/cc'], + ['/../../aa/../bb/cc', '/aa/dd/..', '../bb/cc'], + ['C:/aa/bb/cc', 'C:/aa/dd/..', 'bb/cc'], + ['C:/aa/bb/cc', 'c:/aa/dd/..', 'bb/cc'], + ['c:/aa/../bb/cc', 'c:/aa/dd/..', '../bb/cc'], + ['C:/aa/bb/../../cc', 'C:/aa/../dd/..', 'cc'], + ['C:/../aa/bb/cc', 'C:/aa/dd/..', 'bb/cc'], + ['C:/../../aa/../bb/cc', 'C:/aa/dd/..', '../bb/cc'], ['D:/', 'C:/aa/../bb/cc', 'D:/'], - ['D:/aa/bb', 'C:/aa', 'D:/aa/bb/'], - ['D:/../../aa/../bb/cc', 'C:/aa/dd/..', 'D:/bb/cc/'], + ['D:/aa/bb', 'C:/aa', 'D:/aa/bb'], + ['D:/../../aa/../bb/cc', 'C:/aa/dd/..', 'D:/bb/cc'], ]; if ('\\' === \DIRECTORY_SEPARATOR) { From 4a18f940fbd08df92afc3b7b6de94fe08950e0c6 Mon Sep 17 00:00:00 2001 From: Csaba Maulis Date: Mon, 1 Feb 2021 14:18:43 +0800 Subject: [PATCH 2/2] Replace str_ends_with with substr to maintain PHP 7 compatibility --- src/Symfony/Component/Filesystem/Filesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 5fdf2d470efa..d690ee4adecb 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -479,7 +479,7 @@ public function makePathRelative($endPath, $startPath) $startPathArr = $splitPath($startPath); $endPathArr = $splitPath($endPath); - $pathEnd = str_ends_with($endPath, '/') ? '/' : ''; + $pathEnd = '/' === substr($endPath, -1) ? '/' : ''; if ($endDriveLetter && $startDriveLetter && $endDriveLetter != $startDriveLetter) { // End path is on another drive, so no relative path exists pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy