cms_join_path - backslash considered harmful
Posted: Sat Jul 18, 2009 3:30 pm
A widely supported feature of modern desktop & server operating system is for directory names to consist of words separated by '/' (forward slash). This includes Microsoft Windows (except old versions and special situations such as the cmd.exe shell). There is more on this topic on Wikipedia http://en.wikipedia.org/wiki/Path_(computing). A common misunderstanding is that Windows does not allow '/' in file paths; however in fact within PHP programs it is OK to use '/' in file paths even on Windows.
Because URLs always require forward slashes, it is risky to use code that may produce backslashes in some circumstances. Unfortunately, cms_join_path probably encourages developers to produce strings used both for file paths and URLs which can then cause errors if the code is ported to a Windows server. I found some examples by inspection of the TrueTypeText module, which may produce invalid URLs when running on a Windows server (more details here http://dev.cmsmadesimple.org/feature_request/view/3749)
A simple solution would be to change the function to this:
Rick
Because URLs always require forward slashes, it is risky to use code that may produce backslashes in some circumstances. Unfortunately, cms_join_path probably encourages developers to produce strings used both for file paths and URLs which can then cause errors if the code is ported to a Windows server. I found some examples by inspection of the TrueTypeText module, which may produce invalid URLs when running on a Windows server (more details here http://dev.cmsmadesimple.org/feature_request/view/3749)
A simple solution would be to change the function to this:
Code: Select all
function cms_join_path()
{
$args = func_get_args();
return implode('/',$args);
}