diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-01-25 22:26:47 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2018-01-26 13:38:34 +0100 |
commit | 9ff51aafc518460e6c45996f09e9fe74e5f8d2e8 (patch) | |
tree | 7aa302bf04530f0add196f6bcd6e8636333e6be0 /lib/private/Files | |
parent | b9bbb894f8b01e000bb5e3a8a82db7bebad3ea00 (diff) | |
download | nextcloud-server-9ff51aafc518460e6c45996f09e9fe74e5f8d2e8.tar.gz nextcloud-server-9ff51aafc518460e6c45996f09e9fe74e5f8d2e8.zip |
Use index based string access for substr with length of 1
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib/private/Files')
-rw-r--r-- | lib/private/Files/Filesystem.php | 4 | ||||
-rw-r--r-- | lib/private/Files/Storage/DAV.php | 10 | ||||
-rw-r--r-- | lib/private/Files/View.php | 6 |
3 files changed, 8 insertions, 12 deletions
diff --git a/lib/private/Files/Filesystem.php b/lib/private/Files/Filesystem.php index caf23afba11..95703eab925 100644 --- a/lib/private/Files/Filesystem.php +++ b/lib/private/Files/Filesystem.php @@ -839,8 +839,8 @@ class Filesystem { $path = preg_replace('#/{2,}#', '/', $path); //remove trailing slash - if ($stripTrailingSlash and strlen($path) > 1 and substr($path, -1, 1) === '/') { - $path = substr($path, 0, -1); + if ($stripTrailingSlash and strlen($path) > 1) { + $path = rtrim($path, '/'); } // remove trailing '/.' diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index 43347aa0b8f..f9c6175308c 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -118,13 +118,9 @@ class DAV extends Common { $this->certPath = $certPath; } } - $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 .= '/'; - } + $this->root = $params['root'] ?? '/'; + $this->root = '/' . ltrim($this->root, '/'); + $this->root = rtrim($this->root, '/') . '/'; } else { throw new \Exception('Invalid webdav storage configuration'); } diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index fb0b116666e..1553444e05d 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -698,7 +698,7 @@ class View { // do not allow deleting the root return false; } - $postFix = (substr($path, -1, 1) === '/') ? '/' : ''; + $postFix = (substr($path, -1) === '/') ? '/' : ''; $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); $mount = Filesystem::getMountManager()->find($absolutePath . $postFix); if ($mount and $mount->getInternalPath($absolutePath) === '') { @@ -1067,7 +1067,7 @@ class View { * @return bool|null|string */ public function hash($type, $path, $raw = false) { - $postFix = (substr($path, -1, 1) === '/') ? '/' : ''; + $postFix = (substr($path, -1) === '/') ? '/' : ''; $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); if (Filesystem::isValidPath($path)) { $path = $this->getRelativePath($absolutePath); @@ -1119,7 +1119,7 @@ class View { * \OC\Files\Storage\Storage for delegation to a storage backend for execution */ private function basicOperation($operation, $path, $hooks = [], $extraParam = null) { - $postFix = (substr($path, -1, 1) === '/') ? '/' : ''; + $postFix = (substr($path, -1) === '/') ? '/' : ''; $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); if (Filesystem::isValidPath($path) and !Filesystem::isFileBlacklisted($path) |