Merge pull request #1172 from owncloud/isSubDirectory

Simplify the isSubDirectory() function
This commit is contained in:
Bart Visscher 2013-01-14 12:36:38 -08:00
commit 8b2307ce4b
1 changed files with 4 additions and 24 deletions

View File

@ -625,37 +625,17 @@ class OC_Helper {
return $newpath;
}
/*
* checks if $sub is a subdirectory of $parent
/**
* @brief Checks if $sub is a subdirectory of $parent
*
* @param string $sub
* @param string $parent
* @return bool
*/
public static function issubdirectory($sub, $parent) {
if($sub == null || $sub == '' || $parent == null || $parent == '') {
return false;
if (strpos(realpath($sub), realpath($parent)) === 0) {
return true;
}
$realpath_sub = realpath($sub);
$realpath_parent = realpath($parent);
if(($realpath_sub == false && substr_count($realpath_sub, './') != 0) || ($realpath_parent == false && substr_count($realpath_parent, './') != 0)) { //it checks for both ./ and ../
return false;
}
if($realpath_sub && $realpath_sub != '' && $realpath_parent && $realpath_parent != '') {
if(substr($realpath_sub, 0, strlen($realpath_parent)) == $realpath_parent) {
return true;
}
}else{
if(substr($sub, 0, strlen($parent)) == $parent) {
return true;
}
}
/*echo 'SUB: ' . $sub . "\n";
echo 'PAR: ' . $parent . "\n";
echo 'REALSUB: ' . $realpath_sub . "\n";
echo 'REALPAR: ' . $realpath_parent . "\n";
echo substr($realpath_sub, 0, strlen($realpath_parent));
exit;*/
return false;
}