From 84c9c30b633d42ff574a7cc3e6bb601a674b6773 Mon Sep 17 00:00:00 2001 From: gmsantosxl Date: Wed, 3 Jun 2015 16:48:01 -0300 Subject: [PATCH 1/2] Remove extra '/' when findShortestPath $from is a directory --- src/Composer/Util/Filesystem.php | 13 ++++++++++++- tests/Composer/Test/Util/FilesystemTest.php | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index ca395736f..ab64a49a7 100644 --- a/src/Composer/Util/Filesystem.php +++ b/src/Composer/Util/Filesystem.php @@ -316,7 +316,7 @@ class Filesystem $to = lcfirst($this->normalizePath($to)); if ($directories) { - $from .= '/dummy_file'; + $from .= $this->isDirectory($from) ? 'dummy_file' : '/dummy_file'; } if (dirname($from) === dirname($to)) { @@ -460,6 +460,17 @@ class Filesystem { return (bool) preg_match('{^(file://|/|[a-z]:[\\\\/]|\.\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i', $path); } + + /** + * Return if the given path is a directory + * + * @param string $path + * @return bool + */ + public static function isDirectory($path) + { + return substr($path, -1) === '/'; + } public static function getPlatformPath($path) { diff --git a/tests/Composer/Test/Util/FilesystemTest.php b/tests/Composer/Test/Util/FilesystemTest.php index 8c86c7896..4607512b6 100644 --- a/tests/Composer/Test/Util/FilesystemTest.php +++ b/tests/Composer/Test/Util/FilesystemTest.php @@ -112,6 +112,7 @@ class FilesystemTest extends TestCase array('/foo/bar_vendor', '/foo/bar', '../bar', true), array('/foo/bar_vendor', '/foo/bar/src', '../bar/src', true), array('/foo/bar_vendor/src2', '/foo/bar/src/lib', '../../bar/src/lib', true), + array('C:/', 'C:/foo/bar/', "foo/bar", true), ); } From a060c536bb367c643bbb9d73b4e7b9b4d7beb512 Mon Sep 17 00:00:00 2001 From: gmsantosxl Date: Thu, 4 Jun 2015 14:44:09 -0300 Subject: [PATCH 2/2] Remove extra '/' when findShortestPath $from ends with '/' --- src/Composer/Util/Filesystem.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index ab64a49a7..92e5e0623 100644 --- a/src/Composer/Util/Filesystem.php +++ b/src/Composer/Util/Filesystem.php @@ -316,7 +316,7 @@ class Filesystem $to = lcfirst($this->normalizePath($to)); if ($directories) { - $from .= $this->isDirectory($from) ? 'dummy_file' : '/dummy_file'; + $from = rtrim($from, '/') . '/dummy_file'; } if (dirname($from) === dirname($to)) { @@ -460,17 +460,6 @@ class Filesystem { return (bool) preg_match('{^(file://|/|[a-z]:[\\\\/]|\.\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i', $path); } - - /** - * Return if the given path is a directory - * - * @param string $path - * @return bool - */ - public static function isDirectory($path) - { - return substr($path, -1) === '/'; - } public static function getPlatformPath($path) {