diff --git a/phpBB/phpbb/filesystem/filesystem.php b/phpBB/phpbb/filesystem/filesystem.php index 65585738b2..2931286811 100644 --- a/phpBB/phpbb/filesystem/filesystem.php +++ b/phpBB/phpbb/filesystem/filesystem.php @@ -600,7 +600,7 @@ class filesystem implements filesystem_interface * * @deprecated 3.3.0-a1 (To be removed: 4.0.0) * - * @param string $path + * @param ?string $path * @return bool|string */ protected function phpbb_own_realpath($path) diff --git a/phpBB/phpbb/filesystem/filesystem_interface.php b/phpBB/phpbb/filesystem/filesystem_interface.php index 6d0d35d72f..fa7950dec3 100644 --- a/phpBB/phpbb/filesystem/filesystem_interface.php +++ b/phpBB/phpbb/filesystem/filesystem_interface.php @@ -239,7 +239,7 @@ interface filesystem_interface * Try to resolve realpath when PHP's realpath is not available, or * known to be buggy. * - * @param string $path Path to resolve + * @param ?string $path Path to resolve * * @return string Resolved path */ diff --git a/phpBB/phpbb/storage/adapter/local.php b/phpBB/phpbb/storage/adapter/local.php index 94990a6bf7..ebd8b12ffe 100644 --- a/phpBB/phpbb/storage/adapter/local.php +++ b/phpBB/phpbb/storage/adapter/local.php @@ -230,8 +230,9 @@ class local implements adapter_interface, stream_interface */ protected function ensure_directory_exists($path) { - $path = dirname($this->root_path . $this->get_path($path) . $this->get_filename($path)); - $path = filesystem_helper::make_path_relative($path, $this->root_path); + $absolute_root_path = filesystem_helper::realpath($this->root_path) . DIRECTORY_SEPARATOR; + $path = dirname($absolute_root_path . $this->get_path($path) . $this->get_filename($path)); + $path = filesystem_helper::make_path_relative($path, $absolute_root_path); if (!$this->exists($path)) { @@ -254,11 +255,11 @@ class local implements adapter_interface, stream_interface do { - $parts = explode('/', $path); + $parts = explode(DIRECTORY_SEPARATOR, $path); $parts = array_slice($parts, 0, -1); - $path = implode('/', $parts); + $path = implode(DIRECTORY_SEPARATOR, $parts); } - while ($path && @rmdir($dirpath . '/' . $path)); + while ($path && @rmdir($dirpath . DIRECTORY_SEPARATOR . $path)); } } diff --git a/tests/filesystem/realpath_test.php b/tests/filesystem/realpath_test.php index 145ded7cfa..2b14758ffe 100644 --- a/tests/filesystem/realpath_test.php +++ b/tests/filesystem/realpath_test.php @@ -42,6 +42,7 @@ class phpbb_filesystem_realpath_test extends phpbb_test_case array(__DIR__ . '/../filesystem/../filesystem', __DIR__), array(__DIR__ . '/././', __DIR__), array(__DIR__ . '/non_existent', false), + array(null, getcwd()), array(__FILE__, __FILE__), array(__FILE__ . '../', false),