aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Utils/PathHelper.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Files/Utils/PathHelper.php')
-rw-r--r--lib/private/Files/Utils/PathHelper.php26
1 files changed, 6 insertions, 20 deletions
diff --git a/lib/private/Files/Utils/PathHelper.php b/lib/private/Files/Utils/PathHelper.php
index 07985e884ce..db1294bcc10 100644
--- a/lib/private/Files/Utils/PathHelper.php
+++ b/lib/private/Files/Utils/PathHelper.php
@@ -2,25 +2,9 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-
namespace OC\Files\Utils;
class PathHelper {
@@ -37,7 +21,7 @@ class PathHelper {
}
if ($path === $root) {
return '/';
- } elseif (strpos($path, $root . '/') !== 0) {
+ } elseif (!str_starts_with($path, $root . '/')) {
return null;
} else {
$path = substr($path, strlen($root));
@@ -53,6 +37,8 @@ class PathHelper {
if ($path === '' or $path === '/') {
return '/';
}
+ // No null bytes
+ $path = str_replace(chr(0), '', $path);
//no windows style slashes
$path = str_replace('\\', '/', $path);
//add leading slash
@@ -60,7 +46,7 @@ class PathHelper {
$path = '/' . $path;
}
//remove duplicate slashes
- while (strpos($path, '//') !== false) {
+ while (str_contains($path, '//')) {
$path = str_replace('//', '/', $path);
}
//remove trailing slash