Skip to content

Commit 893df58

Browse files
committed
deprecate relative paths in makePathRelative()
1 parent 12bb22c commit 893df58

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

UPGRADE-3.4.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Filesystem
6666
* The `Symfony\Component\Filesystem\LockHandler` class has been deprecated,
6767
use the `Symfony\Component\Lock\Store\FlockStore` class
6868
or the `Symfony\Component\Lock\Store\FlockStore\SemaphoreStore` class directly instead.
69+
* Support for passing relative paths to `Filesystem::makePathRelative()` is deprecated and will be removed in 4.0.
6970

7071
Finder
7172
------

UPGRADE-4.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ Filesystem
200200
* The `Symfony\Component\Filesystem\LockHandler` has been removed,
201201
use the `Symfony\Component\Lock\Store\FlockStore` class
202202
or the `Symfony\Component\Lock\Store\FlockStore\SemaphoreStore` class directly instead.
203+
* Support for passing relative paths to `Filesystem::makePathRelative()` has been removed.
203204

204205
Finder
205206
------

src/Symfony/Component/Filesystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* added `appendToFile()` to append contents to existing files
8+
* support for passing relative paths to `Filesystem::makePathRelative()` is deprecated and will be removed in 4.0
89

910
3.2.0
1011
-----

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,10 @@ public function readlink($path, $canonicalize = false)
446446
*/
447447
public function makePathRelative($endPath, $startPath)
448448
{
449+
if (!$this->isAbsolutePath($endPath) || !$this->isAbsolutePath($startPath)) {
450+
@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);
451+
}
452+
449453
// Normalize separators on Windows
450454
if ('\\' === DIRECTORY_SEPARATOR) {
451455
$endPath = str_replace('\\', '/', $endPath);
@@ -596,7 +600,7 @@ public function isAbsolutePath($file)
596600
{
597601
return strspn($file, '/\\', 0, 1)
598602
|| (strlen($file) > 3 && ctype_alpha($file[0])
599-
&& ':' === substr($file, 1, 1)
603+
&& ':' === $file[1]
600604
&& strspn($file, '/\\', 2, 1)
601605
)
602606
|| null !== parse_url($file, PHP_URL_SCHEME)

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,6 @@ public function providePathsForMakePathRelative()
11031103
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/src/Symfony/Component/', '../'),
11041104
array('/var/lib/symfony/src/Symfony', '/var/lib/symfony/src/Symfony/Component', '../'),
11051105
array('/var/lib/symfony/src/Symfony', '/var/lib/symfony/src/Symfony/Component/', '../'),
1106-
array('var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component', '../../../'),
11071106
array('/usr/lib/symfony/', '/var/lib/symfony/src/Symfony/Component', '../../../../../../usr/lib/symfony/'),
11081107
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/', 'src/Symfony/'),
11091108
array('/aa/bb', '/aa/bb', './'),
@@ -1145,6 +1144,15 @@ public function providePathsForMakePathRelative()
11451144
return $paths;
11461145
}
11471146

1147+
/**
1148+
* @group legacy
1149+
* @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.
1150+
*/
1151+
public function testMakePathRelativeWithRelativePaths()
1152+
{
1153+
$this->assertSame('../../../', $this->filesystem->makePathRelative('var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component'));
1154+
}
1155+
11481156
public function testMirrorCopiesFilesAndDirectoriesRecursively()
11491157
{
11501158
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;

0 commit comments

Comments
 (0)