1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

Merge pull request #6498 from marc1706/ticket/17141

[ticket/17141] Improve stability of path_helper and increase test coverage
This commit is contained in:
Marc Alexander
2023-06-28 13:39:39 +02:00
2 changed files with 208 additions and 44 deletions

View File

@@ -151,11 +151,6 @@ class path_helper
*/
public function get_web_root_path()
{
if ($this->symfony_request === null)
{
return $this->phpbb_root_path;
}
if (null !== $this->web_root_path)
{
return $this->web_root_path;
@@ -218,7 +213,7 @@ class path_helper
$this->symfony_request->get('_referer'),
$absolute_board_url
);
return $this->web_root_path = $this->phpbb_root_path . $referer_web_root_path;
return $this->web_root_path = $referer_web_root_path;
}
// How many corrections might we need?
@@ -236,7 +231,7 @@ class path_helper
// Prepend ../ to the phpbb_root_path as many times as / exists in path_info
$this->web_root_path = $this->filesystem->clean_path(
'./' . str_repeat('../', $corrections) . $this->phpbb_root_path
'./' . str_repeat('../', max(0, $corrections)) . $this->phpbb_root_path
);
return $this->web_root_path;
}
@@ -264,7 +259,7 @@ class path_helper
$relative_referer_path = substr($relative_referer_path, 0, $has_params);
}
$corrections = substr_count($relative_referer_path, '/');
return $this->phpbb_root_path . str_repeat('../', $corrections - 1);
return $this->phpbb_root_path . str_repeat('../', max(0, $corrections - 1));
}
// If not, it's a bit more complicated. We go to the parent directory