[ticket/16639] Pass absolute paths to make_path_relative

PHPBB3-16639
This commit is contained in:
rubencm 2020-12-07 15:10:26 +01:00
parent c6a202bdb3
commit 3a5a19bd99
4 changed files with 9 additions and 7 deletions

View file

@ -600,7 +600,7 @@ class filesystem implements filesystem_interface
* *
* @deprecated 3.3.0-a1 (To be removed: 4.0.0) * @deprecated 3.3.0-a1 (To be removed: 4.0.0)
* *
* @param string $path * @param ?string $path
* @return bool|string * @return bool|string
*/ */
protected function phpbb_own_realpath($path) protected function phpbb_own_realpath($path)

View file

@ -239,7 +239,7 @@ interface filesystem_interface
* Try to resolve realpath when PHP's realpath is not available, or * Try to resolve realpath when PHP's realpath is not available, or
* known to be buggy. * known to be buggy.
* *
* @param string $path Path to resolve * @param ?string $path Path to resolve
* *
* @return string Resolved path * @return string Resolved path
*/ */

View file

@ -230,8 +230,9 @@ class local implements adapter_interface, stream_interface
*/ */
protected function ensure_directory_exists($path) protected function ensure_directory_exists($path)
{ {
$path = dirname($this->root_path . $this->get_path($path) . $this->get_filename($path)); $absolute_root_path = filesystem_helper::realpath($this->root_path) . DIRECTORY_SEPARATOR;
$path = filesystem_helper::make_path_relative($path, $this->root_path); $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)) if (!$this->exists($path))
{ {
@ -254,11 +255,11 @@ class local implements adapter_interface, stream_interface
do do
{ {
$parts = explode('/', $path); $parts = explode(DIRECTORY_SEPARATOR, $path);
$parts = array_slice($parts, 0, -1); $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));
} }
} }

View file

@ -42,6 +42,7 @@ class phpbb_filesystem_realpath_test extends phpbb_test_case
array(__DIR__ . '/../filesystem/../filesystem', __DIR__), array(__DIR__ . '/../filesystem/../filesystem', __DIR__),
array(__DIR__ . '/././', __DIR__), array(__DIR__ . '/././', __DIR__),
array(__DIR__ . '/non_existent', false), array(__DIR__ . '/non_existent', false),
array(null, getcwd()),
array(__FILE__, __FILE__), array(__FILE__, __FILE__),
array(__FILE__ . '../', false), array(__FILE__ . '../', false),