From 7d052bdbc1e5ec4ee226d9694e9efee7987d0fc9 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 24 Dec 2015 16:19:41 -0500 Subject: [PATCH] Backport 5714cf14a9ca4b439b872aaf3ad6e5bfddda46ad to 2.x Fix file:// paths being mishandled on windows. While I don't think its feasible to fix all the cases reported in #7275 as certain paths have different meaning in windows, we can fix file:// not working. Refs #7275 --- lib/Cake/Test/Case/Utility/FileTest.php | 17 +++++++++++++++++ lib/Cake/Utility/Folder.php | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/FileTest.php b/lib/Cake/Test/Case/Utility/FileTest.php index f596767c4a4..573a7922f42 100644 --- a/lib/Cake/Test/Case/Utility/FileTest.php +++ b/lib/Cake/Test/Case/Utility/FileTest.php @@ -301,6 +301,23 @@ public function testCreate() { $this->assertTrue($File->exists()); } +/** + * 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 * diff --git a/lib/Cake/Utility/Folder.php b/lib/Cake/Utility/Folder.php index 20058f17449..e23f70e5a72 100644 --- a/lib/Cake/Utility/Folder.php +++ b/lib/Cake/Utility/Folder.php @@ -821,13 +821,13 @@ public function errors($reset = true) { * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::realpath */ public function realpath($path) { - $path = str_replace('/', DS, trim($path)); if (strpos($path, '..') === false) { if (!Folder::isAbsolute($path)) { $path = Folder::addPathElement($this->path, $path); } return $path; } + $path = str_replace('/', DS, trim($path)); $parts = explode(DS, $path); $newparts = array(); $newpath = '';