magento-hackathon / magento-composer-installer

Composer installer for Magento modules
210 stars 156 forks source link

Hotfix/double slashes filepath #162

Closed AydinHassan closed 9 years ago

AydinHassan commented 9 years ago

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.

davidverholen commented 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));
AydinHassan commented 9 years ago

:+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

davidverholen commented 9 years ago

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