Permalink
Browse files

[Filesystem] Fix makePathRelative on windows with mixed paths, fix tests

  • Loading branch information...
1 parent 82763b6 commit 0f913fa6efa1b7ac7f77f51c399518e38e952308 @Seldaek Seldaek committed Apr 19, 2012
Showing with 9 additions and 9 deletions.
  1. +8 −2 Filesystem.php
  2. +1 −7 Tests/FilesystemTest.php
View
@@ -181,15 +181,21 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
*/
public function makePathRelative($endPath, $startPath)
{
+ // Normalize separators on windows
+ if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
+ $endPath = strtr($endPath, '\\', '/');
+ $startPath = strtr($startPath, '\\', '/');
+ }
+
// Find for which character the the common path stops
$offset = 0;
while (isset($startPath[$offset]) && isset($endPath[$offset]) && $startPath[$offset] === $endPath[$offset]) {
$offset++;
}
// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
- $diffPath = trim(substr($startPath, $offset), DIRECTORY_SEPARATOR);
- $depth = strlen($diffPath) > 0 ? substr_count($diffPath, DIRECTORY_SEPARATOR) + 1 : 0;
+ $diffPath = trim(substr($startPath, $offset), '/');
+ $depth = strlen($diffPath) > 0 ? substr_count($diffPath, '/') + 1 : 0;
// Repeated "../" for each level need to reach the common path
$traverser = str_repeat('../', $depth);
@@ -460,15 +460,9 @@ public function providePathsForMakePathRelative()
array('var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component', '../../../'),
array('/usr/lib/symfony/', '/var/lib/symfony/src/Symfony/Component', '../../../../../../usr/lib/symfony/'),
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/', 'src/Symfony/'),
+ array('c:\var\lib/symfony/src/Symfony/', 'c:/var/lib/symfony/', 'src/Symfony/'),
);
- // fix directory separator
- foreach ($paths as $i => $pathItems) {
- foreach ($pathItems as $k => $path) {
- $paths[$i][$k] = str_replace('/', DIRECTORY_SEPARATOR, $path);
- }
- }
-
return $paths;
}

0 comments on commit 0f913fa

Please sign in to comment.