1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 05:50:42 +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:
Marc Alexander
2013-12-21 20:08:00 +01:00
parent 235d2069e0
commit d9358c26da
3 changed files with 47 additions and 1 deletions

View File

@@ -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);
}
}