From 5aef69423afdbbb4e8eb29ed74096d7c65675d52 Mon Sep 17 00:00:00 2001 From: bohwaz Date: Tue, 15 Nov 2022 13:07:07 +0100 Subject: [PATCH] Fix issue with brackets in directory names --- index.php | 18 ++++++++++++------ server.php | 14 ++++++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/index.php b/index.php index f24fd62..d907e8b 100644 --- a/index.php +++ b/index.php @@ -1303,13 +1303,19 @@ namespace NanoKaraDAV $this->path = __DIR__ . '/'; } + static protected function glob(string $path, string $pattern = '', int $flags = 0): array + { + $path = preg_replace('/[\*\?\[\]]/', '\\\\$0', $path); + return glob($path . $pattern, $flags); + } + public function list(string $uri, ?array $properties): iterable { - $dirs = glob($this->path . $uri . '/*', \GLOB_ONLYDIR); + $dirs = self::glob($this->path . $uri, '/*', \GLOB_ONLYDIR); $dirs = array_map('basename', $dirs); natcasesort($dirs); - $files = glob($this->path . $uri . '/*'); + $files = self::glob($this->path . $uri, '/*'); $files = array_map('basename', $files); $files = array_diff($files, $dirs); @@ -1486,7 +1492,7 @@ namespace NanoKaraDAV } if (is_dir($target)) { - foreach (glob($target . '/*') as $file) { + foreach (self::glob($target, '/*') as $file) { $this->delete(substr($file, strlen($this->path))); } @@ -1583,7 +1589,7 @@ namespace NanoKaraDAV $last = 0; $path = rtrim($path, '/'); - foreach (glob($path . '/*', GLOB_NOSORT) as $f) { + foreach (self::glob($path, '/*', GLOB_NOSORT) as $f) { if (is_dir($f)) { $m = self::getDirectoryMTime($f); @@ -1651,11 +1657,11 @@ namespace { $fp = fopen(__FILE__, 'r'); if ($relative_uri == 'webdav.js') { - fseek($fp, 43652, SEEK_SET); + fseek($fp, 43873, SEEK_SET); echo fread($fp, 24265); } else { - fseek($fp, 43652 + 24265, SEEK_SET); + fseek($fp, 43873 + 24265, SEEK_SET); echo fread($fp, 6760); } diff --git a/server.php b/server.php index 44ffc46..c293598 100644 --- a/server.php +++ b/server.php @@ -27,13 +27,19 @@ namespace NanoKaraDAV $this->path = __DIR__ . '/'; } + static protected function glob(string $path, string $pattern = '', int $flags = 0): array + { + $path = preg_replace('/[\*\?\[\]]/', '\\\\$0', $path); + return glob($path . $pattern, $flags); + } + public function list(string $uri, ?array $properties): iterable { - $dirs = glob($this->path . $uri . '/*', \GLOB_ONLYDIR); + $dirs = self::glob($this->path . $uri, '/*', \GLOB_ONLYDIR); $dirs = array_map('basename', $dirs); natcasesort($dirs); - $files = glob($this->path . $uri . '/*'); + $files = self::glob($this->path . $uri, '/*'); $files = array_map('basename', $files); $files = array_diff($files, $dirs); @@ -210,7 +216,7 @@ namespace NanoKaraDAV } if (is_dir($target)) { - foreach (glob($target . '/*') as $file) { + foreach (self::glob($target, '/*') as $file) { $this->delete(substr($file, strlen($this->path))); } @@ -307,7 +313,7 @@ namespace NanoKaraDAV $last = 0; $path = rtrim($path, '/'); - foreach (glob($path . '/*', GLOB_NOSORT) as $f) { + foreach (self::glob($path, '/*', GLOB_NOSORT) as $f) { if (is_dir($f)) { $m = self::getDirectoryMTime($f);