Skip to content

Commit abab929

Browse files
committed
Prevent empty value in isAbsolutePath, use rtrim in mirror
1 parent f5c99d2 commit abab929

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)