Use index based string access for substr with length of 1

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Morris Jobke 2018-01-25 22:26:47 +01:00
parent b9bbb894f8
commit 9ff51aafc5
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
12 changed files with 24 additions and 46 deletions

View File

@ -61,10 +61,7 @@ class OwnCloud extends \OC\Files\Storage\DAV{
} }
if (isset($params['root'])){ if (isset($params['root'])){
$root = $params['root']; $root = '/' . ltrim($params['root'], '/');
if (substr($root, 0, 1) !== '/'){
$root = '/' . $root;
}
} }
else{ else{
$root = '/'; $root = '/';

View File

@ -103,13 +103,8 @@ class SFTP extends \OC\Files\Storage\Common {
$this->root $this->root
= isset($params['root']) ? $this->cleanPath($params['root']) : '/'; = isset($params['root']) ? $this->cleanPath($params['root']) : '/';
if ($this->root[0] !== '/') { $this->root = '/' . ltrim($this->root, '/');
$this->root = '/' . $this->root; $this->root = rtrim($this->root, '/') . '/';
}
if (substr($this->root, -1, 1) !== '/') {
$this->root .= '/';
}
} }
/** /**

View File

@ -84,13 +84,9 @@ class SMB extends Common implements INotifyStorage {
} }
$this->share = $this->server->getShare(trim($params['share'], '/')); $this->share = $this->server->getShare(trim($params['share'], '/'));
$this->root = isset($params['root']) ? $params['root'] : '/'; $this->root = $params['root'] ?? '/';
if (!$this->root || $this->root[0] !== '/') { $this->root = '/' . ltrim($this->root, '/');
$this->root = '/' . $this->root; $this->root = rtrim($this->root, '/') . '/';
}
if (substr($this->root, -1, 1) !== '/') {
$this->root .= '/';
}
} else { } else {
throw new \Exception('Invalid configuration'); throw new \Exception('Invalid configuration');
} }

View File

@ -63,11 +63,10 @@ class VersionParser {
if(!$this->isValidVersionString($firstVersionNumber)) { if(!$this->isValidVersionString($firstVersionNumber)) {
break; break;
} }
if(substr($firstVersion, 0, 1) === '>') { if(strpos($firstVersion, '>') === 0) {
return new Version($firstVersionNumber, ''); return new Version($firstVersionNumber, '');
} else {
return new Version('', $firstVersionNumber);
} }
return new Version('', $firstVersionNumber);
case 2: case 2:
if(!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) { if(!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) {
break; break;

View File

@ -91,9 +91,7 @@ class TAR extends Archive {
*/ */
public function addFolder($path) { public function addFolder($path) {
$tmpBase = \OC::$server->getTempManager()->getTemporaryFolder(); $tmpBase = \OC::$server->getTempManager()->getTemporaryFolder();
if (substr($path, -1, 1) != '/') { $path = rtrim($path, '/') . '/';
$path .= '/';
}
if ($this->fileExists($path)) { if ($this->fileExists($path)) {
return false; return false;
} }
@ -297,10 +295,7 @@ class TAR extends Archive {
if ((array_search($path, $files) !== false) or (array_search($path . '/', $files) !== false)) { if ((array_search($path, $files) !== false) or (array_search($path . '/', $files) !== false)) {
return true; return true;
} else { } else {
$folderPath = $path; $folderPath = rtrim($path, '/') . '/';
if (substr($folderPath, -1, 1) != '/') {
$folderPath .= '/';
}
$pathLength = strlen($folderPath); $pathLength = strlen($folderPath);
foreach ($files as $file) { foreach ($files as $file) {
if (strlen($file) > $pathLength and substr($file, 0, $pathLength) == $folderPath) { if (strlen($file) > $pathLength and substr($file, 0, $pathLength) == $folderPath) {

View File

@ -263,7 +263,7 @@ class Avatar implements IAvatar {
* @return string * @return string
*/ */
private function generateAvatar($userDisplayName, $size) { private function generateAvatar($userDisplayName, $size) {
$text = strtoupper(substr($userDisplayName, 0, 1)); $text = strtoupper($userDisplayName[0]);
$backgroundColor = $this->avatarBackgroundColor($userDisplayName); $backgroundColor = $this->avatarBackgroundColor($userDisplayName);
$im = imagecreatetruecolor($size, $size); $im = imagecreatetruecolor($size, $size);

View File

@ -839,8 +839,8 @@ class Filesystem {
$path = preg_replace('#/{2,}#', '/', $path); $path = preg_replace('#/{2,}#', '/', $path);
//remove trailing slash //remove trailing slash
if ($stripTrailingSlash and strlen($path) > 1 and substr($path, -1, 1) === '/') { if ($stripTrailingSlash and strlen($path) > 1) {
$path = substr($path, 0, -1); $path = rtrim($path, '/');
} }
// remove trailing '/.' // remove trailing '/.'

View File

@ -118,13 +118,9 @@ class DAV extends Common {
$this->certPath = $certPath; $this->certPath = $certPath;
} }
} }
$this->root = isset($params['root']) ? $params['root'] : '/'; $this->root = $params['root'] ?? '/';
if (!$this->root || $this->root[0] != '/') { $this->root = '/' . ltrim($this->root, '/');
$this->root = '/' . $this->root; $this->root = rtrim($this->root, '/') . '/';
}
if (substr($this->root, -1, 1) != '/') {
$this->root .= '/';
}
} else { } else {
throw new \Exception('Invalid webdav storage configuration'); throw new \Exception('Invalid webdav storage configuration');
} }

View File

@ -698,7 +698,7 @@ class View {
// do not allow deleting the root // do not allow deleting the root
return false; return false;
} }
$postFix = (substr($path, -1, 1) === '/') ? '/' : ''; $postFix = (substr($path, -1) === '/') ? '/' : '';
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
$mount = Filesystem::getMountManager()->find($absolutePath . $postFix); $mount = Filesystem::getMountManager()->find($absolutePath . $postFix);
if ($mount and $mount->getInternalPath($absolutePath) === '') { if ($mount and $mount->getInternalPath($absolutePath) === '') {
@ -1067,7 +1067,7 @@ class View {
* @return bool|null|string * @return bool|null|string
*/ */
public function hash($type, $path, $raw = false) { public function hash($type, $path, $raw = false) {
$postFix = (substr($path, -1, 1) === '/') ? '/' : ''; $postFix = (substr($path, -1) === '/') ? '/' : '';
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
if (Filesystem::isValidPath($path)) { if (Filesystem::isValidPath($path)) {
$path = $this->getRelativePath($absolutePath); $path = $this->getRelativePath($absolutePath);
@ -1119,7 +1119,7 @@ class View {
* \OC\Files\Storage\Storage for delegation to a storage backend for execution * \OC\Files\Storage\Storage for delegation to a storage backend for execution
*/ */
private function basicOperation($operation, $path, $hooks = [], $extraParam = null) { private function basicOperation($operation, $path, $hooks = [], $extraParam = null) {
$postFix = (substr($path, -1, 1) === '/') ? '/' : ''; $postFix = (substr($path, -1) === '/') ? '/' : '';
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
if (Filesystem::isValidPath($path) if (Filesystem::isValidPath($path)
and !Filesystem::isFileBlacklisted($path) and !Filesystem::isFileBlacklisted($path)

View File

@ -519,7 +519,7 @@ class Installer {
foreach(\OC::$APPSROOTS as $app_dir) { foreach(\OC::$APPSROOTS as $app_dir) {
if($dir = opendir( $app_dir['path'] )) { if($dir = opendir( $app_dir['path'] )) {
while( false !== ( $filename = readdir( $dir ))) { while( false !== ( $filename = readdir( $dir ))) {
if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) { if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) {
if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) {
if(!Installer::isInstalled($filename)) { if(!Installer::isInstalled($filename)) {
$info=OC_App::getAppInfo($filename); $info=OC_App::getAppInfo($filename);

View File

@ -208,7 +208,7 @@ class PersonalInfo implements ISettings {
$l = \OC::$server->getL10N('settings', $lang); $l = \OC::$server->getL10N('settings', $lang);
// TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
$potentialName = (string) $l->t('__language_name__'); $potentialName = (string) $l->t('__language_name__');
if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file if($l->getLanguageCode() === $lang && $potentialName[0] !== '_') {//first check if the language name is in the translation file
$ln = array('code' => $lang, 'name' => $potentialName); $ln = array('code' => $lang, 'name' => $potentialName);
} elseif ($lang === 'en') { } elseif ($lang === 'en') {
$ln = ['code' => $lang, 'name' => 'English (US)']; $ln = ['code' => $lang, 'name' => 'English (US)'];

View File

@ -784,16 +784,16 @@ class OC_Image implements \OCP\IImage {
$color[1] = (($color[1] & 0xf800) >> 8) * 65536 + (($color[1] & 0x07e0) >> 3) * 256 + (($color[1] & 0x001f) << 3); $color[1] = (($color[1] & 0xf800) >> 8) * 65536 + (($color[1] & 0x07e0) >> 3) * 256 + (($color[1] & 0x001f) << 3);
break; break;
case 8: case 8:
$color = @unpack('n', $vide . substr($data, $p, 1)); $color = @unpack('n', $vide . ($data[$p] ?? ''));
$color[1] = (isset($palette[$color[1] + 1])) ? $palette[$color[1] + 1] : $palette[1]; $color[1] = (isset($palette[$color[1] + 1])) ? $palette[$color[1] + 1] : $palette[1];
break; break;
case 4: case 4:
$color = @unpack('n', $vide . substr($data, floor($p), 1)); $color = @unpack('n', $vide . ($data[floor($p)] ?? ''));
$color[1] = ($p * 2) % 2 == 0 ? $color[1] >> 4 : $color[1] & 0x0F; $color[1] = ($p * 2) % 2 == 0 ? $color[1] >> 4 : $color[1] & 0x0F;
$color[1] = (isset($palette[$color[1] + 1])) ? $palette[$color[1] + 1] : $palette[1]; $color[1] = (isset($palette[$color[1] + 1])) ? $palette[$color[1] + 1] : $palette[1];
break; break;
case 1: case 1:
$color = @unpack('n', $vide . substr($data, floor($p), 1)); $color = @unpack('n', $vide . ($data[floor($p)] ?? ''));
switch (($p * 8) % 8) { switch (($p * 8) % 8) {
case 0: case 0:
$color[1] = $color[1] >> 7; $color[1] = $color[1] >> 7;