From 893df5804e82150dc6b3a3b32f53a7e93642e58e Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 14 Sep 2017 14:29:42 +0200 Subject: [PATCH] deprecate relative paths in makePathRelative() --- UPGRADE-3.4.md | 1 + UPGRADE-4.0.md | 1 + src/Symfony/Component/Filesystem/CHANGELOG.md | 1 + src/Symfony/Component/Filesystem/Filesystem.php | 6 +++++- .../Component/Filesystem/Tests/FilesystemTest.php | 10 +++++++++- 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/UPGRADE-3.4.md b/UPGRADE-3.4.md index 33147c4cc9..7c575cfc2d 100644 --- a/UPGRADE-3.4.md +++ b/UPGRADE-3.4.md @@ -66,6 +66,7 @@ Filesystem * The `Symfony\Component\Filesystem\LockHandler` class has been deprecated, use the `Symfony\Component\Lock\Store\FlockStore` class or the `Symfony\Component\Lock\Store\FlockStore\SemaphoreStore` class directly instead. + * Support for passing relative paths to `Filesystem::makePathRelative()` is deprecated and will be removed in 4.0. Finder ------ diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 6c32bad70c..983c7f72fb 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -200,6 +200,7 @@ Filesystem * The `Symfony\Component\Filesystem\LockHandler` has been removed, use the `Symfony\Component\Lock\Store\FlockStore` class or the `Symfony\Component\Lock\Store\FlockStore\SemaphoreStore` class directly instead. + * Support for passing relative paths to `Filesystem::makePathRelative()` has been removed. Finder ------ diff --git a/src/Symfony/Component/Filesystem/CHANGELOG.md b/src/Symfony/Component/Filesystem/CHANGELOG.md index 4a275e86f0..ba3eff0f0d 100644 --- a/src/Symfony/Component/Filesystem/CHANGELOG.md +++ b/src/Symfony/Component/Filesystem/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG ----- * added `appendToFile()` to append contents to existing files + * support for passing relative paths to `Filesystem::makePathRelative()` is deprecated and will be removed in 4.0 3.2.0 ----- diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 2e742d532a..2548c19646 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -446,6 +446,10 @@ class Filesystem */ public function makePathRelative($endPath, $startPath) { + if (!$this->isAbsolutePath($endPath) || !$this->isAbsolutePath($startPath)) { + @trigger_error(sprintf('Support for passing relative paths to %s() is deprecated since version 3.4 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED); + } + // Normalize separators on Windows if ('\\' === DIRECTORY_SEPARATOR) { $endPath = str_replace('\\', '/', $endPath); @@ -596,7 +600,7 @@ class Filesystem { return strspn($file, '/\\', 0, 1) || (strlen($file) > 3 && ctype_alpha($file[0]) - && ':' === substr($file, 1, 1) + && ':' === $file[1] && strspn($file, '/\\', 2, 1) ) || null !== parse_url($file, PHP_URL_SCHEME) diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index 4420e8fb85..9b6da0d66d 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -1103,7 +1103,6 @@ class FilesystemTest extends FilesystemTestCase 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('/aa/bb', '/aa/bb', './'), @@ -1145,6 +1144,15 @@ class FilesystemTest extends FilesystemTestCase return $paths; } + /** + * @group legacy + * @expectedDeprecation Support for passing relative paths to Symfony\Component\Filesystem\Filesystem::makePathRelative() is deprecated since version 3.4 and will be removed in 4.0. + */ + public function testMakePathRelativeWithRelativePaths() + { + $this->assertSame('../../../', $this->filesystem->makePathRelative('var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component')); + } + public function testMirrorCopiesFilesAndDirectoriesRecursively() { $sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;