mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
adding fix for Folder path, #2983
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5483 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
797b10f0ed
commit
2d7be853ce
2 changed files with 22 additions and 18 deletions
|
@ -87,14 +87,15 @@ class Folder extends Object{
|
||||||
if (empty($path)) {
|
if (empty($path)) {
|
||||||
$path = TMP;
|
$path = TMP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($mode) {
|
if ($mode) {
|
||||||
$this->mode = intval($mode, 8);
|
$this->mode = intval($mode, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_exists($path) && $create == true) {
|
if (!file_exists($path) && $create == true) {
|
||||||
$this->create($path, $this->mode);
|
$this->create($path, $this->mode);
|
||||||
}
|
}
|
||||||
|
if($path{0} != '/') {
|
||||||
|
$path = realpath($path);
|
||||||
|
}
|
||||||
$this->cd($path);
|
$this->cd($path);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -115,9 +116,6 @@ class Folder extends Object{
|
||||||
*/
|
*/
|
||||||
function cd($path) {
|
function cd($path) {
|
||||||
$path = $this->realpath($path);
|
$path = $this->realpath($path);
|
||||||
if (!$this->isAbsolute($path)) {
|
|
||||||
$path = $this->addPathElement($this->path, $path);
|
|
||||||
}
|
|
||||||
if (is_dir($path) && file_exists($path)) {
|
if (is_dir($path) && file_exists($path)) {
|
||||||
return $this->path = $path;
|
return $this->path = $path;
|
||||||
}
|
}
|
||||||
|
@ -325,7 +323,7 @@ class Folder extends Object{
|
||||||
*/
|
*/
|
||||||
function inCakePath($path = '') {
|
function inCakePath($path = '') {
|
||||||
$dir = substr($this->slashTerm(ROOT), 0, -1);
|
$dir = substr($this->slashTerm(ROOT), 0, -1);
|
||||||
$newdir = $this->slashTerm($dir . $path);
|
$newdir = $dir . $path;
|
||||||
return $this->inPath($newdir);
|
return $this->inPath($newdir);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -335,18 +333,13 @@ class Folder extends Object{
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function inPath($path = '', $reverse = false) {
|
function inPath($path = '', $reverse = false) {
|
||||||
if (!$this->isAbsolute($path)) {
|
$dir = $this->slashTerm($path);
|
||||||
$path = $this->addPathElement($this->path, $path);
|
$current = $this->slashTerm($this->pwd());
|
||||||
}
|
|
||||||
$path = $this->realpath($path);
|
|
||||||
$dir = substr($this->slashTerm($path), 0, -1);
|
|
||||||
|
|
||||||
if (!$reverse) {
|
if (!$reverse) {
|
||||||
$return = preg_match('/^' . preg_quote($this->slashTerm($dir), '/') . '(.*)/', $this->slashTerm($this->pwd()));
|
$return = preg_match('/^(.*)' . preg_quote($dir, '/') . '(.*)/', $current);
|
||||||
} else {
|
} else {
|
||||||
$return = preg_match('/^' . preg_quote($this->slashTerm($this->pwd()), '/') . '(.*)/', $this->slashTerm($dir));
|
$return = preg_match('/^(.*)' . preg_quote($current, '/') . '(.*)/', $dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($return == 1) {
|
if ($return == 1) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -690,6 +683,9 @@ class Folder extends Object{
|
||||||
function realpath($path) {
|
function realpath($path) {
|
||||||
$path = trim($path);
|
$path = trim($path);
|
||||||
if (strpos($path, '..') === false) {
|
if (strpos($path, '..') === false) {
|
||||||
|
if (!$this->isAbsolute($path)) {
|
||||||
|
$path = $this->addPathElement($this->path, $path);
|
||||||
|
}
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
$parts = explode(DS, $path);
|
$parts = explode(DS, $path);
|
||||||
|
|
|
@ -78,10 +78,13 @@ class FolderTest extends UnitTestCase {
|
||||||
$result = $this->Folder->isSlashTerm($inside);
|
$result = $this->Folder->isSlashTerm($inside);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
//$result = $this->Folder->inPath('tests/');
|
$result = $this->Folder->realpath('tests/');
|
||||||
//$this->assertTrue($result);
|
$this->assertEqual($result, $path . DS .'tests/');
|
||||||
|
|
||||||
$result = $this->Folder->inPath(DS . 'non-existing' . DS . $inside);
|
$result = $this->Folder->inPath('tests/');
|
||||||
|
$this->assertTrue($result);
|
||||||
|
|
||||||
|
$result = $this->Folder->inPath(DS . 'non-existing' . $inside);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,5 +124,10 @@ class FolderTest extends UnitTestCase {
|
||||||
|
|
||||||
//pr($this->Folder->errors());
|
//pr($this->Folder->errors());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testRealPathForWebroot() {
|
||||||
|
$Folder = new Folder('files/');
|
||||||
|
$this->assertEqual(realpath('files/'), $Folder->path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
Add table
Reference in a new issue