Skip to content

Commit

Permalink
Fix file:// paths being mishandled on windows.
Browse files Browse the repository at this point in the history
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 22, 2015
1 parent a026b0c commit 5714cf1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/Filesystem/Folder.php
Expand Up @@ -286,7 +286,6 @@ public static function isAbsolute($path)
if (empty($path)) {
return false;
}

return $path[0] === '/' ||
preg_match('/^[A-Z]:\\\\/i', $path) ||
substr($path, 0, 2) === '\\\\' ||
Expand Down Expand Up @@ -827,13 +826,13 @@ public function errors($reset = true)
*/
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 = '';
Expand Down
20 changes: 18 additions & 2 deletions 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)
*
Expand Down Expand Up @@ -293,6 +291,24 @@ 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

0 comments on commit 5714cf1

Please sign in to comment.