Closed AydinHassan closed 9 years ago
here is a little codesnippet that normalizes any weird paths like /./ or multiple ////// and changes / and \ to the systems DIRECTORY_SEPARATOR (this is not always right, but mostly when working with filesystems)
$path = str_replace(
array('/./', '\\.\\', '\\'),
DIRECTORY_SEPARATOR,
$path
);
$doubleDs = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
do {
$path = str_replace($doubleDs, DIRECTORY_SEPARATOR, $path);
} while (false !== strpos($path, $doubleDs));
:+1: I did think of just replacing them at the end but I thought it would be better to fix where the double //
were actually coming from
yes that's right ;) I just thought this might be useful. I use this code (in an own function) for every operation where I manipulate or build file paths, so they get always eliminated without having to care about
I found a wierd bug that I only notices when automatically adding files to the gitignore. It seems PHP or the OS does not care about double slashed in paths. Eg this is a valid path:
/app/etc/modules//EcomDev_PHPUnit.xml
This has taken me almost a day to reproduce in code, it seems this issue only occurs when the destination directory exists and the source is a glob. I've added a failing unit test and then the second commit fixes the current issue. Who knows if it breaks something else though! - however all the other tests do pass on my machine.