From 81e41bac4bd7f5ffdee90531cd0a706026053402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Fri, 7 Jun 2013 13:20:17 +0200 Subject: [PATCH] Fixed the Filesystem methods for a directory with a name that is a substring of a another directory --- src/Composer/Util/Filesystem.php | 4 ++-- tests/Composer/Test/Util/FilesystemTest.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index 693bbc5ad..413dac882 100644 --- a/src/Composer/Util/Filesystem.php +++ b/src/Composer/Util/Filesystem.php @@ -213,7 +213,7 @@ class Filesystem return './'.basename($to); } - $commonPath = $to; + $commonPath = $to.'/'; while (strpos($from, $commonPath) !== 0 && '/' !== $commonPath && !preg_match('{^[a-z]:/?$}i', $commonPath) && '.' !== $commonPath) { $commonPath = strtr(dirname($commonPath), '\\', '/'); } @@ -250,7 +250,7 @@ class Filesystem return $directories ? '__DIR__' : '__FILE__'; } - $commonPath = $to; + $commonPath = $to.'/'; while (strpos($from, $commonPath) !== 0 && '/' !== $commonPath && !preg_match('{^[a-z]:/?$}i', $commonPath) && '.' !== $commonPath) { $commonPath = strtr(dirname($commonPath), '\\', '/'); } diff --git a/tests/Composer/Test/Util/FilesystemTest.php b/tests/Composer/Test/Util/FilesystemTest.php index e04167023..88fad9289 100644 --- a/tests/Composer/Test/Util/FilesystemTest.php +++ b/tests/Composer/Test/Util/FilesystemTest.php @@ -58,6 +58,8 @@ class FilesystemTest extends TestCase array('/tmp/test/.././vendor', '/tmp/test', true, "dirname(__DIR__).'/test'"), array('C:/Temp', 'c:\Temp\..\..\test', true, "dirname(__DIR__).'/test'"), array('C:/Temp/../..', 'd:\Temp\..\..\test', true, "'d:/test'"), + array('/foo/bar', '/foo/bar_vendor', true, "dirname(__DIR__).'/bar_vendor'"), + array('/foo/bar_vendor', '/foo/bar', true, "dirname(__DIR__).'/bar'"), ); } @@ -103,6 +105,8 @@ class FilesystemTest extends TestCase array('C:/Temp', 'c:\Temp\..\..\test', "../test", true), array('C:/Temp/../..', 'c:\Temp\..\..\test', "./test", true), array('/tmp', '/tmp/../../test', '/test', true), + array('/foo/bar', '/foo/bar_vendor', '../bar_vendor', true), + array('/foo/bar_vendor', '/foo/bar', '../bar', true), ); }