Skip to content

Commit

Permalink
ensure url encoded pathes are handled correct, fixes #104
Browse files Browse the repository at this point in the history
  • Loading branch information
mikey179 committed Mar 29, 2015
1 parent c775dfd commit 03a3899
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

* fixed #107: touch() does not respect file permissions
* fixed #105: vfs directory structure is not reset after each test
* fixed #104: vfsStream can't handle url encoded pathes


1.4.0 (2014-09-14)
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/org/bovigo/vfs/vfsStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static function path($url)
$path = str_replace('\\', '/', $path);
// replace double slashes with single slashes
$path = str_replace('//', '/', $path);
return $path;
return urldecode($path);
}

/**
Expand Down
51 changes: 51 additions & 0 deletions src/test/php/org/bovigo/vfs/Issue104TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* This file is part of vfsStream.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package org\bovigo\vfs
*/
namespace org\bovigo\vfs;
/**
* @group issue_104
*/
class Issue104TestCase extends \PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function vfsStreamCanHandleUrlEncodedPathPassedByInternalPhpCode()
{
$structure = array('foo bar' => array(
'schema.xsd' => '<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="myType"></xs:complexType>
</xs:schema>',
)
);
vfsStream::setup('root', null, $structure);
$doc = new \DOMDocument();
$this->assertTrue($doc->load(vfsStream::url('root/foo bar/schema.xsd')));
}

/**
* @test
*/
public function vfsStreamCanHandleUrlEncodedPath()
{
$content = '<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="myType"></xs:complexType>
</xs:schema>';
$structure = array('foo bar' => array(
'schema.xsd' => $content,
)
);
vfsStream::setup('root', null, $structure);
$this->assertEquals(
$content,
file_get_contents(vfsStream::url('root/foo%20bar/schema.xsd'))
);
}
}

0 comments on commit 03a3899

Please sign in to comment.