Skip to content

Commit 1d7501d

Browse files
committed
merged branch stealth35/fs_micropt (PR symfony#4568)
Commits ------- abab929 Prevent empty value in isAbsolutePath, use rtrim in mirror Discussion ---------- Prevent empty value in isAbsolutePath, use rtrim in mirror Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: [![Build Status](https://secure.travis-ci.org/stealth35/symfony.png?branch=fs_micropt)](http://travis-ci.org/stealth35/symfony) --------------------------------------------------------------------------- by travisbot at 2012-06-13T13:39:39Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1610607) (merged abab929 into 3ab9a6e).
2 parents 3ab9a6e + abab929 commit 1d7501d

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,8 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
226226
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($originDir, $flags), \RecursiveIteratorIterator::SELF_FIRST);
227227
}
228228

229-
if ('/' === substr($targetDir, -1) || '\\' === substr($targetDir, -1)) {
230-
$targetDir = substr($targetDir, 0, -1);
231-
}
232-
233-
if ('/' === substr($originDir, -1) || '\\' === substr($originDir, -1)) {
234-
$originDir = substr($originDir, 0, -1);
235-
}
229+
$targetDir = rtrim($targetDir, '/\\');
230+
$originDir = rtrim($originDir, '/\\');
236231

237232
foreach ($iterator as $file) {
238233
$target = str_replace($originDir, $targetDir, $file->getPathname());
@@ -258,10 +253,10 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
258253
*/
259254
public function isAbsolutePath($file)
260255
{
261-
if ($file[0] == '/' || $file[0] == '\\'
256+
if (strspn($file, '/\\', 0, 1)
262257
|| (strlen($file) > 3 && ctype_alpha($file[0])
263-
&& $file[1] == ':'
264-
&& ($file[2] == '\\' || $file[2] == '/')
258+
&& substr($file, 1, 1) === ':'
259+
&& (strspn($file, '/\\', 2, 1))
265260
)
266261
|| null !== parse_url($file, PHP_URL_SCHEME)
267262
) {

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,9 @@ public function providePathsForIsAbsolutePath()
564564
array('c:\\\\var\\lib', true),
565565
array('\\var\\lib', true),
566566
array('var/lib', false),
567-
array('../var/lib', false)
567+
array('../var/lib', false),
568+
array('', false),
569+
array(null, false)
568570
);
569571
}
570572

0 commit comments

Comments
 (0)