Don't use substr to get first char of string

This commit is contained in:
Bart Visscher 2012-06-08 21:23:25 +02:00
parent bb649dd0d5
commit cff1b6e699
13 changed files with 20 additions and 20 deletions

View File

@ -18,7 +18,7 @@ class OC_Filestorage_Archive extends OC_Filestorage_Common{
private static $rootView; private static $rootView;
private function stripPath($path){//files should never start with / private function stripPath($path){//files should never start with /
if(substr($path,0,1)=='/'){ if(!$path || $path[0]=='/'){
$path=substr($path,1); $path=substr($path,1);
} }
return $path; return $path;

View File

@ -21,7 +21,7 @@ class OC_FileStorage_FTP extends OC_Filestorage_Common{
$this->password=$params['password']; $this->password=$params['password'];
$this->secure=isset($params['secure'])?(bool)$params['secure']:false; $this->secure=isset($params['secure'])?(bool)$params['secure']:false;
$this->root=isset($params['root'])?$params['root']:'/'; $this->root=isset($params['root'])?$params['root']:'/';
if(substr($this->root,0,1)!='/'){ if(!$this->root || $this->root[0]!='/'){
$this->root='/'.$this->root; $this->root='/'.$this->root;
} }

View File

@ -269,7 +269,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
$this->user=$params['user']; $this->user=$params['user'];
$this->root=isset($params['root'])?$params['root']:'/'; $this->root=isset($params['root'])?$params['root']:'/';
$this->secure=isset($params['secure'])?(bool)$params['secure']:true; $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->root='/'.$this->root;
} }
$this->auth = new CF_Authentication($this->user, $this->token, null, $this->host); $this->auth = new CF_Authentication($this->user, $this->token, null, $this->host);

View File

@ -25,7 +25,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
$this->password=$params['password']; $this->password=$params['password'];
$this->secure=isset($params['secure'])?(bool)$params['secure']:false; $this->secure=isset($params['secure'])?(bool)$params['secure']:false;
$this->root=isset($params['root'])?$params['root']:'/'; $this->root=isset($params['root'])?$params['root']:'/';
if(substr($this->root,0,1)!='/'){ if(!$this->root || $this->root[0]!='/'){
$this->root='/'.$this->root; $this->root='/'.$this->root;
} }
if(substr($this->root,-1,1)!='/'){ if(substr($this->root,-1,1)!='/'){
@ -273,7 +273,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
} }
private function cleanPath($path){ private function cleanPath($path){
if(substr($path,0,1)=='/'){ if(!$path || $path[0]=='/'){
return substr($path,1); return substr($path,1);
}else{ }else{
return $path; return $path;

View File

@ -606,7 +606,7 @@ class OC_LDAP {
static private function combineFilter($filters, $operator) { static private function combineFilter($filters, $operator) {
$combinedFilter = '('.$operator; $combinedFilter = '('.$operator;
foreach($filters as $filter) { foreach($filters as $filter) {
if(substr($filter,0,1) != '(') { if($filter[0] != '(') {
$filter = '('.$filter.')'; $filter = '('.$filter.')';
} }
$combinedFilter.=$filter; $combinedFilter.=$filter;
@ -722,4 +722,4 @@ class OC_LDAP {
return false; return false;
} }
} }

View File

@ -494,7 +494,7 @@ class OC_App{
$apps=array(); $apps=array();
$dh=opendir(OC::$APPSROOT.'/apps'); $dh=opendir(OC::$APPSROOT.'/apps');
while($file=readdir($dh)){ 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; $apps[]=$file;
} }
} }

View File

@ -150,7 +150,7 @@ class OC_Archive_TAR extends OC_Archive{
$folderContent=array(); $folderContent=array();
$pathLength=strlen($path); $pathLength=strlen($path);
foreach($files as $file){ foreach($files as $file){
if(substr($file,0,1)=='/'){ if($file[0]=='/'){
$file=substr($file,1); $file=substr($file,1);
} }
if(substr($file,0,$pathLength)==$path and $file!=$path){ 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); return $this->fileExists('/'.$path);
}else{ }else{
return false; return false;

View File

@ -191,7 +191,7 @@ class OC_Archive_ZIP extends OC_Archive{
} }
private function stripPath($path){ private function stripPath($path){
if(substr($path,0,1)=='/'){ if(!$path || $path[0]=='/'){
return substr($path,1); return substr($path,1);
}else{ }else{
return $path; return $path;

View File

@ -150,7 +150,7 @@ class OC_Filesystem{
if(!$path){ if(!$path){
$path='/'; $path='/';
} }
if(substr($path,0,1)!=='/'){ if($path[0]!=='/'){
$path='/'.$path; $path='/'.$path;
} }
$foundMountPoint=''; $foundMountPoint='';
@ -311,12 +311,12 @@ class OC_Filesystem{
* @param string mountpoint * @param string mountpoint
*/ */
static public function mount($class,$arguments,$mountpoint){ static public function mount($class,$arguments,$mountpoint){
if($mountpoint[0]!='/'){
$mountpoint='/'.$mountpoint;
}
if(substr($mountpoint,-1)!=='/'){ if(substr($mountpoint,-1)!=='/'){
$mountpoint=$mountpoint.'/'; $mountpoint=$mountpoint.'/';
} }
if(substr($mountpoint,0,1)!=='/'){
$mountpoint='/'.$mountpoint;
}
self::$mounts[$mountpoint]=array('class'=>$class,'arguments'=>$arguments); self::$mounts[$mountpoint]=array('class'=>$class,'arguments'=>$arguments);
} }
@ -361,7 +361,7 @@ class OC_Filesystem{
* @return bool * @return bool
*/ */
static public function isValidPath($path){ static public function isValidPath($path){
if(substr($path,0,1)!=='/'){ if(!$path || $path[0]!=='/'){
$path='/'.$path; $path='/'.$path;
} }
if(strstr($path,'/../') || strrchr($path, '/') === '/..' ){ if(strstr($path,'/../') || strrchr($path, '/') === '/..' ){

View File

@ -34,7 +34,7 @@ class OC_FilesystemView {
if(!$path){ if(!$path){
$path='/'; $path='/';
} }
if(substr($path,0,1)!=='/'){ if($path[0]!=='/'){
$path='/'.$path; $path='/'.$path;
} }
return $this->fakeRoot.$path; return $this->fakeRoot.$path;

View File

@ -110,7 +110,7 @@ class OC_Installer{
//try to find it in a subdir //try to find it in a subdir
$dh=opendir($extractDir); $dh=opendir($extractDir);
while($folder=readdir($dh)){ 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')){ if(is_file($extractDir.'/'.$folder.'/appinfo/info.xml')){
$extractDir.='/'.$folder; $extractDir.='/'.$folder;
} }

View File

@ -129,7 +129,7 @@ class OC_User_Database extends OC_User_Backend {
$row=$result->fetchRow(); $row=$result->fetchRow();
if($row){ if($row){
$storedHash=$row['password']; $storedHash=$row['password'];
if (substr($storedHash,0,1)=='$'){//the new phpass based hashing if ($storedHash[0]=='$'){//the new phpass based hashing
$hasher=$this->getHasher(); $hasher=$this->getHasher();
if($hasher->CheckPassword($password.OC_Config::getValue('passwordsalt', ''), $storedHash)){ if($hasher->CheckPassword($password.OC_Config::getValue('passwordsalt', ''), $storedHash)){
return $row['uid']; return $row['uid'];

View File

@ -41,7 +41,7 @@ function loadTests($dir=''){
$test=isset($_GET['test'])?$_GET['test']:false; $test=isset($_GET['test'])?$_GET['test']:false;
if($dh=opendir($dir)){ if($dh=opendir($dir)){
while($name=readdir($dh)){ while($name=readdir($dh)){
if(substr($name,0,1)!='.'){//no hidden files, '.' or '..' if($name[0]!='.'){//no hidden files, '.' or '..'
$file=$dir.'/'.$name; $file=$dir.'/'.$name;
if(is_dir($file)){ if(is_dir($file)){
loadTests($file); loadTests($file);