Skip to content

Commit

Permalink
Prevent empty value in isAbsolutePath, use rtrim in mirror
Browse files Browse the repository at this point in the history
  • Loading branch information
stealth35 committed Jun 13, 2012
1 parent f5c99d2 commit abab929
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
15 changes: 5 additions & 10 deletions src/Symfony/Component/Filesystem/Filesystem.php
Expand Up @@ -226,13 +226,8 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($originDir, $flags), \RecursiveIteratorIterator::SELF_FIRST);
}

if ('/' === substr($targetDir, -1) || '\\' === substr($targetDir, -1)) {
$targetDir = substr($targetDir, 0, -1);
}

if ('/' === substr($originDir, -1) || '\\' === substr($originDir, -1)) {
$originDir = substr($originDir, 0, -1);
}
$targetDir = rtrim($targetDir, '/\\');
$originDir = rtrim($originDir, '/\\');

foreach ($iterator as $file) {
$target = str_replace($originDir, $targetDir, $file->getPathname());
Expand All @@ -258,10 +253,10 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
*/
public function isAbsolutePath($file)
{
if ($file[0] == '/' || $file[0] == '\\'
if (strspn($file, '/\\', 0, 1)
|| (strlen($file) > 3 && ctype_alpha($file[0])
&& $file[1] == ':'
&& ($file[2] == '\\' || $file[2] == '/')
&& substr($file, 1, 1) === ':'
&& (strspn($file, '/\\', 2, 1))
)
|| null !== parse_url($file, PHP_URL_SCHEME)
) {
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Expand Up @@ -564,7 +564,9 @@ public function providePathsForIsAbsolutePath()
array('c:\\\\var\\lib', true),
array('\\var\\lib', true),
array('var/lib', false),
array('../var/lib', false)
array('../var/lib', false),
array('', false),
array(null, false)
);
}

Expand Down

0 comments on commit abab929

Please sign in to comment.