Prevent empty value in isAbsolutePath, use rtrim in mirror
This commit is contained in:
parent
f5c99d2421
commit
abab929516
@ -226,13 +226,8 @@ class Filesystem
|
|||||||
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($originDir, $flags), \RecursiveIteratorIterator::SELF_FIRST);
|
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($originDir, $flags), \RecursiveIteratorIterator::SELF_FIRST);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('/' === substr($targetDir, -1) || '\\' === substr($targetDir, -1)) {
|
$targetDir = rtrim($targetDir, '/\\');
|
||||||
$targetDir = substr($targetDir, 0, -1);
|
$originDir = rtrim($originDir, '/\\');
|
||||||
}
|
|
||||||
|
|
||||||
if ('/' === substr($originDir, -1) || '\\' === substr($originDir, -1)) {
|
|
||||||
$originDir = substr($originDir, 0, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($iterator as $file) {
|
foreach ($iterator as $file) {
|
||||||
$target = str_replace($originDir, $targetDir, $file->getPathname());
|
$target = str_replace($originDir, $targetDir, $file->getPathname());
|
||||||
@ -258,10 +253,10 @@ class Filesystem
|
|||||||
*/
|
*/
|
||||||
public function isAbsolutePath($file)
|
public function isAbsolutePath($file)
|
||||||
{
|
{
|
||||||
if ($file[0] == '/' || $file[0] == '\\'
|
if (strspn($file, '/\\', 0, 1)
|
||||||
|| (strlen($file) > 3 && ctype_alpha($file[0])
|
|| (strlen($file) > 3 && ctype_alpha($file[0])
|
||||||
&& $file[1] == ':'
|
&& substr($file, 1, 1) === ':'
|
||||||
&& ($file[2] == '\\' || $file[2] == '/')
|
&& (strspn($file, '/\\', 2, 1))
|
||||||
)
|
)
|
||||||
|| null !== parse_url($file, PHP_URL_SCHEME)
|
|| null !== parse_url($file, PHP_URL_SCHEME)
|
||||||
) {
|
) {
|
||||||
|
@ -564,7 +564,9 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase
|
|||||||
array('c:\\\\var\\lib', true),
|
array('c:\\\\var\\lib', true),
|
||||||
array('\\var\\lib', true),
|
array('\\var\\lib', true),
|
||||||
array('var/lib', false),
|
array('var/lib', false),
|
||||||
array('../var/lib', false)
|
array('../var/lib', false),
|
||||||
|
array('', false),
|
||||||
|
array(null, false)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user