]> source.dussan.org Git - nextcloud-server.git/commitdiff
Don't use substr to get first char of string
authorBart Visscher <bartv@thisnet.nl>
Fri, 8 Jun 2012 19:23:25 +0000 (21:23 +0200)
committerBart Visscher <bartv@thisnet.nl>
Fri, 8 Jun 2012 19:38:10 +0000 (21:38 +0200)
14 files changed:
apps/files_archive/lib/storage.php
apps/files_external/lib/ftp.php
apps/files_external/lib/smb.php
apps/files_external/lib/swift.php
apps/files_external/lib/webdav.php
apps/user_ldap/lib_ldap.php
lib/app.php
lib/archive/tar.php
lib/archive/zip.php
lib/filesystem.php
lib/filesystemview.php
lib/installer.php
lib/user/database.php
tests/index.php

index b8f7d4683850371f735dfac623dd7c0c15747df2..86761663611cf5c4462f12f72df28d673a4df462 100644 (file)
@@ -18,7 +18,7 @@ class OC_Filestorage_Archive extends OC_Filestorage_Common{
        private static $rootView;
        
        private function stripPath($path){//files should never start with /
-               if(substr($path,0,1)=='/'){
+               if(!$path || $path[0]=='/'){
                        $path=substr($path,1);
                }
                return $path;
index e9655ebf3a5f45997cc5eb2aaba274b6b29abb4e..4d5ae670de59c2ff341671e15365f8362d621795 100644 (file)
@@ -21,7 +21,7 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{
                $this->password=$params['password'];
                $this->secure=isset($params['secure'])?(bool)$params['secure']:false;
                $this->root=isset($params['root'])?$params['root']:'/';
-               if(substr($this->root,0,1)!='/'){
+               if(!$this->root || $this->root[0]!='/'){
                        $this->root='/'.$this->root;
                }
                
index f594fbb880d951a8682f8ddce97ce72035aa7d40..9112655194a4aef59ee76b57383e4456e66249a9 100644 (file)
@@ -23,13 +23,13 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{
                $this->password=$params['password'];
                $this->share=$params['share'];
                $this->root=isset($params['root'])?$params['root']:'/';
+               if(!$this->root || $this->root[0]!='/'){
+                       $this->root='/'.$this->root;
+               }
                if(substr($this->root,-1,1)!='/'){
                        $this->root.='/';
                }
-               if(substr($this->root,0,1)!='/'){
-                       $this->root='/'.$this->root;
-               }
-               if(substr($this->share,0,1)!='/'){
+               if(!$this->share || $this->share[0]!='/'){
                        $this->share='/'.$this->share;
                }
                if(substr($this->share,-1,1)=='/'){
index e3ba9c240cf7e511ef2b6221f326e9e6ff366a0e..58b95a6ae010cdec9373c76d0c35811546746ec6 100644 (file)
@@ -269,7 +269,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
                $this->user=$params['user'];
                $this->root=isset($params['root'])?$params['root']:'/';
                $this->secure=isset($params['secure'])?(bool)$params['secure']:true;
-               if(substr($this->root,0,1)!='/'){
+               if(!$this->root || $this->root[0]!='/'){
                        $this->root='/'.$this->root;
                }
                $this->auth = new CF_Authentication($this->user, $this->token, null, $this->host);
index 07c90d4878e94b208b3abd1f4c610ba25195f19a..d136f04f3eb5e7f90ea5bd7c2ffbbc761b0ee256 100644 (file)
@@ -25,7 +25,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
                $this->password=$params['password'];
                $this->secure=isset($params['secure'])?(bool)$params['secure']:false;
                $this->root=isset($params['root'])?$params['root']:'/';
-               if(substr($this->root,0,1)!='/'){
+               if(!$this->root || $this->root[0]!='/'){
                        $this->root='/'.$this->root;
                }
                if(substr($this->root,-1,1)!='/'){
@@ -273,7 +273,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
        }
 
        private function cleanPath($path){
-               if(substr($path,0,1)=='/'){
+               if(!$path || $path[0]=='/'){
                        return substr($path,1);
                }else{
                        return $path;
index 22d464b65a21229192580df54783f939cceff51d..befdf267bcdeb1b779c2cb74e554fce9ea73f89d 100644 (file)
@@ -576,7 +576,7 @@ class OC_LDAP {
        static private function combineFilter($filters, $operator) {
                $combinedFilter = '('.$operator;
                foreach($filters as $filter) {
-                   if(substr($filter,0,1) != '(') {
+                   if($filter[0] != '(') {
                                $filter = '('.$filter.')';
                    }
                    $combinedFilter.=$filter;
@@ -692,4 +692,4 @@ class OC_LDAP {
                return false;
        }
 
- }
\ No newline at end of file
+ }
index e8a5a1291d912e3706ec0708d52e65f0e166a52d..0c51e3c55325e46118c8e8ac8bf6c384352b206c 100755 (executable)
@@ -469,7 +469,7 @@ class OC_App{
                $apps=array();
                $dh=opendir(OC::$APPSROOT.'/apps');
                while($file=readdir($dh)){
-                       if(substr($file,0,1)!='.' and is_file(OC::$APPSROOT.'/apps/'.$file.'/appinfo/app.php')){
+                       if($file[0]!='.' and is_file(OC::$APPSROOT.'/apps/'.$file.'/appinfo/app.php')){
                                $apps[]=$file;
                        }
                }
index 4ff787798340ac0a2e547c38ca3a62e8c1bf987d..944a0ac4ba4e13d5ba738e9daff66027763e1551 100644 (file)
@@ -150,7 +150,7 @@ class OC_Archive_TAR extends OC_Archive{
                $folderContent=array();
                $pathLength=strlen($path);
                foreach($files as $file){
-                       if(substr($file,0,1)=='/'){
+                       if($file[0]=='/'){
                                $file=substr($file,1);
                        }
                        if(substr($file,0,$pathLength)==$path and $file!=$path){
@@ -241,7 +241,7 @@ class OC_Archive_TAR extends OC_Archive{
                                }
                        }
                }
-               if(substr($path,0,1)!='/'){//not all programs agree on the use of a leading /
+               if($path[0]!='/'){//not all programs agree on the use of a leading /
                        return $this->fileExists('/'.$path);
                }else{
                        return false;
index 22ab48937ebadaa9fb87e13e1a516d0c019aa4bb..6631a649b169380bebfea156f94a539135d7924d 100644 (file)
@@ -191,7 +191,7 @@ class OC_Archive_ZIP extends OC_Archive{
        }
 
        private function stripPath($path){
-               if(substr($path,0,1)=='/'){
+               if(!$path || $path[0]=='/'){
                        return substr($path,1);
                }else{
                        return $path;
index 43d743b639d9e517daa037b992c31803e92d0406..337b0f1464bd26350cdc4e800bb1570b1f894ac0 100644 (file)
@@ -150,7 +150,7 @@ class OC_Filesystem{
                if(!$path){
                        $path='/';
                }
-               if(substr($path,0,1)!=='/'){
+               if($path[0]!=='/'){
                        $path='/'.$path;
                }
                $foundMountPoint='';
@@ -313,12 +313,12 @@ class OC_Filesystem{
        * @param string mountpoint
        */
        static public function mount($class,$arguments,$mountpoint){
+               if($mountpoint[0]!='/'){
+                       $mountpoint='/'.$mountpoint;
+               }
                if(substr($mountpoint,-1)!=='/'){
                        $mountpoint=$mountpoint.'/';
                }
-               if(substr($mountpoint,0,1)!=='/'){
-                       $mountpoint='/'.$mountpoint;
-               }
                self::$mounts[$mountpoint]=array('class'=>$class,'arguments'=>$arguments);
        }
 
@@ -349,7 +349,7 @@ class OC_Filesystem{
         * @return bool
         */
        static public function isValidPath($path){
-               if(substr($path,0,1)!=='/'){
+               if(!$path || $path[0]!=='/'){
                        $path='/'.$path;
                }
                if(strstr($path,'/../') || strrchr($path, '/') === '/..' ){
index 8aa7b49f4137975d279c799ace374f60bcf87bdc..6e34257a46046bde245b1313946749ea61894b7a 100644 (file)
@@ -51,7 +51,7 @@ class OC_FilesystemView {
                if(!$path){
                        $path='/';
                }
-               if(substr($path,0,1)!=='/'){
+               if($path[0]!=='/'){
                        $path='/'.$path;
                }
                return $this->fakeRoot.$path;
index 5c030d2917df12b988bac504eb7b5419bd17f299..34c6f8c7bb98dd1ab42ad856836f1a62adfe0e70 100644 (file)
@@ -110,7 +110,7 @@ class OC_Installer{
                        //try to find it in a subdir
                        $dh=opendir($extractDir);
                        while($folder=readdir($dh)){
-                               if(substr($folder,0,1)!='.' and is_dir($extractDir.'/'.$folder)){
+                               if($folder[0]!='.' and is_dir($extractDir.'/'.$folder)){
                                        if(is_file($extractDir.'/'.$folder.'/appinfo/info.xml')){
                                                $extractDir.='/'.$folder;
                                        }
index bb077c8364f0045b0cc4d83dde83caeb3f1c6b21..a48b8357d6427b3b89a03442471fd26c68ed54ae 100644 (file)
@@ -129,7 +129,7 @@ class OC_User_Database extends OC_User_Backend {
                $row=$result->fetchRow();
                if($row){
                        $storedHash=$row['password'];
-                       if (substr($storedHash,0,1)=='$'){//the new phpass based hashing
+                       if ($storedHash[0]=='$'){//the new phpass based hashing
                                $hasher=$this->getHasher();
                                if($hasher->CheckPassword($password.OC_Config::getValue('passwordsalt', ''), $storedHash)){
                                        return $row['uid'];
index 9c5178f81a829052a0d5a19c552d9c9fd4f09c13..691bf2a5d45a1dfa195b314c0f9b255ffdfcac41 100644 (file)
@@ -47,7 +47,7 @@ function loadTests($dir=''){
        }
        if($dh=opendir($dir)){
                while($name=readdir($dh)){
-                       if(substr($name,0,1)!='.'){//no hidden files, '.' or '..'
+                       if($name[0]!='.'){//no hidden files, '.' or '..'
                                $file=$dir.'/'.$name;
                                if(is_dir($file)){
                                        loadTests($file);