Skip to content
Permalink
Browse files

Update isAbsolute() to recognize stream wrapper paths.

This has the benefit that the realpath() method is not applied to a
registered stream wrapper in the constructor of the Folder class.
Using the realpath() method will break the stream.

Thank "davalb" for the original patch.
  • Loading branch information...
ADmad committed Jun 22, 2014
1 parent 497ecd3 commit 9a1a965b1c99564afd31cf305377390521690bd1
Showing with 26 additions and 1 deletion.
  1. +3 −0 lib/Cake/Test/Case/Utility/FolderTest.php
  2. +23 −1 lib/Cake/Utility/Folder.php
@@ -548,13 +548,16 @@ public function testIsAbsolute() {
$this->assertFalse(Folder::isAbsolute('0:\\path\\to\\file'));
$this->assertFalse(Folder::isAbsolute('\\path/to/file'));
$this->assertFalse(Folder::isAbsolute('\\path\\to\\file'));
$this->assertFalse(Folder::isAbsolute('notRegisteredStreamWrapper://example'));
$this->assertFalse(Folder::isAbsolute('://example'));
$this->assertTrue(Folder::isAbsolute('/usr/local'));
$this->assertTrue(Folder::isAbsolute('//path/to/file'));
$this->assertTrue(Folder::isAbsolute('C:\\cake'));
$this->assertTrue(Folder::isAbsolute('C:\\path\\to\\file'));
$this->assertTrue(Folder::isAbsolute('d:\\path\\to\\file'));
$this->assertTrue(Folder::isAbsolute('\\\\vmware-host\\Shared Folders\\file'));
$this->assertTrue(Folder::isAbsolute('http://www.example.com'));
}
/**
@@ -278,7 +278,29 @@ public static function isWindowsPath($path) {
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::isAbsolute
*/
public static function isAbsolute($path) {
return !empty($path) && ($path[0] === '/' || preg_match('/^[A-Z]:\\\\/i', $path) || substr($path, 0, 2) === '\\\\');
if (empty($path)) {
return false;
}
return $path[0] === '/' ||
preg_match('/^[A-Z]:\\\\/i', $path) ||
substr($path, 0, 2) === '\\\\' ||
self::isRegisteredStreamWrapper($path);
}
/**
* Returns true if given $path is a registered stream wrapper.
*
* @param string $path Path to check
* @return boolean true If path is registered stream wrapper.
*/
public static function isRegisteredStreamWrapper($path) {
if (preg_match('/^[A-Z]+(?=:\/\/)/i', $path, $matches) &&
in_array($matches[0], stream_get_wrappers())
) {
return true;
}
return false;
}
/**

0 comments on commit 9a1a965

Please sign in to comment.
You can’t perform that action at this time.