Skip to content
This repository has been archived by the owner on Jan 8, 2021. It is now read-only.

Commit

Permalink
fix by converting getcwd() to UTF-8
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jun 17, 2014
1 parent 1692f95 commit aa2a1bf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
15 changes: 11 additions & 4 deletions class/Patchwork/Utf8/WinFsStreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,30 @@ static function hide($path)
return true;
}

static function fs($path)
static function fs($path, $is_utf8 = true)
{
static $fs;
isset($fs) or $fs = new \COM('Scripting.FileSystemObject', null, CP_UTF8);

list(,$path) = explode('://', $path, 2);
$path = explode('://', $path, 2);
$path = $path[(int) isset($path[1])];
$path = strtr($path, '/', '\\');
$pre = '';

if (! isset($path[0])
|| ( '/' !== $path[0]
&& '\\' !== $path[0]
&& false === strpos($path, ':') ) )
{
$path = getcwd() . '\\' . $path;
$pre = getcwd() . '\\';
}

return array($fs, $path);
$pre = new \VARIANT($pre);

if ($is_utf8) $path = new \VARIANT($path, VT_BSTR, CP_UTF8);
else $path = new \VARIANT($path);

return array($fs, $fs->getAbsolutePathName(variant_cat($pre, $path)));
}

function dir_closedir()
Expand Down
26 changes: 21 additions & 5 deletions tests/Patchwork/Tests/Utf8/WinFsStreamWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ class WinFsStreamWrapperTest extends \PHPUnit_Framework_TestCase

static function setUpBeforeClass()
{
self::$dir = 'win://' . __DIR__ . '/../µ€';
stream_wrapper_register('win', 'Patchwork\Utf8\WinFsStreamWrapper');
extension_loaded('com_dotnet') and mkdir(self::$dir);
if (extension_loaded('com_dotnet'))
{
stream_wrapper_register('win', 'Patchwork\Utf8\WinFsStreamWrapper');
$dir = __DIR__;
list(,$dir) = \Patchwork\Utf8\WinFsStreamWrapper::fs($dir, false); // Convert $dir to UTF-8
self::$dir = 'win://' . $dir . '/../µ€';
mkdir(self::$dir);
}
}

static function tearDownAfterClass()
Expand All @@ -32,16 +37,27 @@ static function tearDownAfterClass()
{
list($fs, $path) = \Patchwork\Utf8\WinFsStreamWrapper::fs(self::$dir);
if ($fs->FolderExists($path)) $fs->GetFolder($path)->Delete(true);
stream_wrapper_unregister('win');
}

stream_wrapper_unregister('win');
}

function setUp()
{
if (! extension_loaded('com_dotnet')) $this->markTestSkipped('Extension com_dotnet is required.');
}

/**
* @covers Patchwork\Utf8\WinFsStreamWrapper::fs
*/
function testRelDir()
{
$this->assertTrue(file_exists(self::$dir));
$cwd = getcwd();
chdir(__DIR__ . '/..');
$this->assertTrue(file_exists('win://./µ€'));
chdir($cwd);
}

/**
* @covers Patchwork\Utf8\WinFsStreamWrapper::dir_opendir
* @covers Patchwork\Utf8\WinFsStreamWrapper::dir_readdir
Expand Down

0 comments on commit aa2a1bf

Please sign in to comment.