Browse Source

Remove extra '/' when findShortestPath $from is a directory

gmsantosxl 10 years ago
parent
commit
84c9c30b63
2 changed files with 13 additions and 1 deletions
  1. 12 1
      src/Composer/Util/Filesystem.php
  2. 1 0
      tests/Composer/Test/Util/FilesystemTest.php

+ 12 - 1
src/Composer/Util/Filesystem.php

@@ -316,7 +316,7 @@ class Filesystem
         $to = lcfirst($this->normalizePath($to));
         $to = lcfirst($this->normalizePath($to));
 
 
         if ($directories) {
         if ($directories) {
-            $from .= '/dummy_file';
+            $from .= $this->isDirectory($from) ? 'dummy_file' : '/dummy_file';
         }
         }
 
 
         if (dirname($from) === dirname($to)) {
         if (dirname($from) === dirname($to)) {
@@ -460,6 +460,17 @@ class Filesystem
     {
     {
         return (bool) preg_match('{^(file://|/|[a-z]:[\\\\/]|\.\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i', $path);
         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)
     public static function getPlatformPath($path)
     {
     {

+ 1 - 0
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', '../bar', true),
             array('/foo/bar_vendor', '/foo/bar/src', '../bar/src', 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('/foo/bar_vendor/src2', '/foo/bar/src/lib', '../../bar/src/lib', true),
+            array('C:/', 'C:/foo/bar/', "foo/bar", true),
         );
         );
     }
     }