Skip to content

Commit

Permalink
Backport 5714cf1 to 2.x
Browse files Browse the repository at this point in the history
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
  • Loading branch information
markstory committed Dec 24, 2015
1 parent 73badc9 commit 7d052bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions lib/Cake/Test/Case/Utility/FileTest.php
Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Utility/Folder.php
Expand Up @@ -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 = '';
Expand Down

0 comments on commit 7d052bd

Please sign in to comment.