From 9ff51aafc518460e6c45996f09e9fe74e5f8d2e8 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 25 Jan 2018 22:26:47 +0100 Subject: Use index based string access for substr with length of 1 Signed-off-by: Morris Jobke --- lib/private/Files/Filesystem.php | 4 ++-- lib/private/Files/Storage/DAV.php | 10 +++------- lib/private/Files/View.php | 6 +++--- 3 files changed, 8 insertions(+), 12 deletions(-) (limited to 'lib/private/Files') 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) -- cgit v1.2.3