浏览代码

Merge pull request #5635 from ndm2/3.0-fix-handling-of-non-existent-paths

3.0 - Fix partial path being set for non existent paths
Mark Story 11 年之前
父节点
当前提交
e0e6bc39bf
共有 2 个文件被更改,包括 17 次插入1 次删除
  1. 4 1
      src/Filesystem/File.php
  2. 13 0
      tests/TestCase/Filesystem/FileTest.php

+ 4 - 1
src/Filesystem/File.php

@@ -391,7 +391,10 @@ class File
     public function pwd()
     public function pwd()
     {
     {
         if ($this->path === null) {
         if ($this->path === null) {
-            $this->path = $this->Folder->slashTerm($this->Folder->pwd()) . $this->name;
+            $dir = $this->Folder->pwd();
+            if (is_dir($dir)) {
+                $this->path = $this->Folder->slashTerm($dir) . $this->name;
+            }
         }
         }
         return $this->path;
         return $this->path;
     }
     }

+ 13 - 0
tests/TestCase/Filesystem/FileTest.php

@@ -622,4 +622,17 @@ class FileTest extends TestCase
 
 
         $TmpFile->delete();
         $TmpFile->delete();
     }
     }
+
+    /**
+     * Tests that no path is being set for passed file paths that
+     * do not exist.
+     *
+     * @return void
+     */
+    public function testNoPartialPathBeingSetForNonExistentPath()
+    {
+        $TmpFile = new File('/non/existent/file');
+        $this->assertNull($TmpFile->pwd());
+        $this->assertNull($TmpFile->path);
+    }
 }
 }