diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 5211841fc02..3f4331420a1 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -751,12 +751,14 @@ function dol_delete_file($file,$disableglob=0,$nophperrors=0,$nohook=0,$object=n { $error=0; - //print "x".$file." ".$disableglob; + //print "x".$file." ".$disableglob;exit; $ok=true; $file_osencoded=dol_osencode($file); // New filename encoded in OS filesystem encoding charset if (empty($disableglob) && ! empty($file_osencoded)) { - foreach (glob($file_osencoded) as $filename) + $globencoded=str_replace('[','\[',$file_osencoded); + $globencoded=str_replace(']','\]',$globencoded); + foreach (glob($globencoded) as $filename) { if ($nophperrors) $ok=@unlink($filename); // The unlink encapsulated by dolibarr else $ok=unlink($filename); // The unlink encapsulated by dolibarr diff --git a/test/phpunit/FilesLibTest.php b/test/phpunit/FilesLibTest.php index 7a3d0f10aa9..17d36944f86 100644 --- a/test/phpunit/FilesLibTest.php +++ b/test/phpunit/FilesLibTest.php @@ -326,7 +326,7 @@ class FilesLibTest extends PHPUnit_Framework_TestCase // Again to test with overwriting=1 $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv',0,1); print __METHOD__." result=".$result."\n"; - $this->assertGreaterThanOrEqual(1,$result); // Should be 1 + $this->assertGreaterThanOrEqual(1,$result,'copy destination already exists, overwrite'); // Should be 1 // Again to test with overwriting=1 $result=dol_move($conf->admin->dir_temp.'/file.csv',$conf->admin->dir_temp.'/file2.csv',0,1); @@ -340,7 +340,17 @@ class FilesLibTest extends PHPUnit_Framework_TestCase // Again to test no erreor when deleteing a non existing file $result=dol_delete_file($conf->admin->dir_temp.'/file2.csv'); print __METHOD__." result=".$result."\n"; - $this->assertTrue($result); + $this->assertTrue($result,'delete file that does not exists'); + + // Test copy with special char / delete with blob + $result=dol_copy($file, $conf->admin->dir_temp.'/file with [x] and é.csv',0,1); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThanOrEqual(1,$result,'copy file with special char, overwrite'); // Should be 1 + + // Try to delete using a glob criteria + $result=dol_delete_file($conf->admin->dir_temp.'/file with [x]*é.csv'); + print __METHOD__." result=".$result."\n"; + $this->assertTrue($result,'delete file using glob criteria'); } /** @@ -377,4 +387,4 @@ class FilesLibTest extends PHPUnit_Framework_TestCase $this->assertEquals(0,count($result)); } } -?> \ No newline at end of file +?>