Skip to content

Commit

Permalink
#11749 Attempt to fix UTF8 filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
burzum authored and saeideng committed Mar 22, 2018
1 parent 7e9218c commit a6e1fad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Filesystem/File.php
Expand Up @@ -15,6 +15,7 @@
namespace Cake\Filesystem;

use finfo;
use SplFileInfo;

/**
* Convenience class for reading, writing and appending to files.
Expand Down Expand Up @@ -82,9 +83,10 @@ class File
*/
public function __construct($path, $create = false, $mode = 0755)
{
$this->Folder = new Folder(dirname($path), $create, $mode);
$splInfo = new SplFileInfo($path);
$this->Folder = new Folder($splInfo->getPath(), $create, $mode);
if (!is_dir($path)) {
$this->name = basename($path);
$this->name = $splInfo->getBasename();
}
$this->pwd();
$create && !$this->exists() && $this->safe($path) && $this->create();
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/Filesystem/FileTest.php
Expand Up @@ -123,6 +123,20 @@ function_exists('mime_content_type') &&
$this->assertInstanceOf('Cake\Filesystem\Folder', $result);
}

/**
* testUtf8Filenames
*
* @link https://github.com/cakephp/cakephp/issues/11749
* @return void
*/
public function testUtf8Filenames()
{
$File = new File(TMP . 'tests/permissions/نام فارسی.php', true);
$this->assertEquals('نام فارسی', $File->name());
$this->assertTrue($File->exists());
$this->assertTrue($File->readable());
}

/**
* testPermission method
*
Expand Down

0 comments on commit a6e1fad

Please sign in to comment.