Browse Source

Merge pull request #7892 from cakephp/issue-7275

Fix file:// paths being mishandled on windows.
José Lorenzo Rodríguez 10 years ago
parent
commit
cf680a4302
2 changed files with 19 additions and 4 deletions
  1. 1 2
      src/Filesystem/Folder.php
  2. 18 2
      tests/TestCase/Filesystem/FileTest.php

+ 1 - 2
src/Filesystem/Folder.php

@@ -286,7 +286,6 @@ class Folder
         if (empty($path)) {
             return false;
         }
-
         return $path[0] === '/' ||
             preg_match('/^[A-Z]:\\\\/i', $path) ||
             substr($path, 0, 2) === '\\\\' ||
@@ -827,13 +826,13 @@ class Folder
      */
     public function realpath($path)
     {
-        $path = str_replace('/', DIRECTORY_SEPARATOR, trim($path));
         if (strpos($path, '..') === false) {
             if (!Folder::isAbsolute($path)) {
                 $path = Folder::addPathElement($this->path, $path);
             }
             return $path;
         }
+        $path = str_replace('/', DIRECTORY_SEPARATOR, trim($path));
         $parts = explode(DIRECTORY_SEPARATOR, $path);
         $newparts = [];
         $newpath = '';

+ 18 - 2
tests/TestCase/Filesystem/FileTest.php

@@ -1,7 +1,5 @@
 <?php
 /**
- * FileTest file
- *
  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  *
@@ -294,6 +292,24 @@ class FileTest extends TestCase
     }
 
     /**
+     * Tests the exists() method.
+     *
+     * @return void
+     */
+    public function testExists()
+    {
+        $tmpFile = TMP . 'tests/cakephp.file.test.tmp';
+        $file = new File($tmpFile, true, 0777);
+        $this->assertTrue($file->exists(), 'absolute path should exist');
+
+        $file = new File('file://' . $tmpFile, false);
+        $this->assertTrue($file->exists(), 'file:// should exist.');
+
+        $file = new File('/something/bad', false);
+        $this->assertFalse($file->exists(), 'missing file should not exist.');
+    }
+
+    /**
      * testOpeningNonExistentFileCreatesIt method
      *
      * @return void