summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2013-01-14 12:36:38 -0800
committerBart Visscher <bartv@thisnet.nl>2013-01-14 12:36:38 -0800
commit8b2307ce4b258f103506f85e787acbd552e83302 (patch)
treefe13fb6f8e9d532c794e917248b4a9a0b89fb0e1
parent7455056d2d2839f2888c7dcc6ca76339c2238118 (diff)
parent99adfbdb8663d89b650feab6b797f344a46c82f3 (diff)
downloadnextcloud-server-8b2307ce4b258f103506f85e787acbd552e83302.tar.gz
nextcloud-server-8b2307ce4b258f103506f85e787acbd552e83302.zip
Merge pull request #1172 from owncloud/isSubDirectory
Simplify the isSubDirectory() function
-rw-r--r--lib/helper.php28
1 files changed, 4 insertions, 24 deletions
diff --git a/lib/helper.php b/lib/helper.php
index 1aba2a38100..e7c9ac8015d 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -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;
- }
- $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;
- }
+ if (strpos(realpath($sub), realpath($parent)) === 0) {
+ 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;
}