mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +02:00
[ticket/11997] Add clean_url() method to path_helper
This method will get rid of unnecessary . and .. in URLs. PHPBB3-11997
This commit is contained in:
@@ -207,4 +207,27 @@ class path_helper
|
||||
|
||||
return generate_board_url() . $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Eliminates useless . and .. components from specified URL
|
||||
*
|
||||
* @param string $url URL to clean
|
||||
*
|
||||
* @return string Cleaned URL
|
||||
*/
|
||||
public function clean_url($url)
|
||||
{
|
||||
$delimiter_position = strpos($url, '://');
|
||||
// URL should contain :// but it shouldn't start with it.
|
||||
// Do not clean URLs that do not fit these constraints.
|
||||
if (empty($delimiter_position))
|
||||
{
|
||||
return $url;
|
||||
}
|
||||
$scheme = substr($url, 0, $delimiter_position) . '://';
|
||||
// Add length of URL delimiter to position
|
||||
$path = substr($url, $delimiter_position + 3);
|
||||
|
||||
return $scheme . $this->filesystem->clean_path($path);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user