Closed Sanderluc5 closed 3 years ago
This is because of https://github.com/bovigo/vfsStream/issues/211. vfsStream doesn't support a blank name (/
) for root. So what's happening is it thinks etc
is root and won't let you create files above that level.
If you modify your test slightly, things work:
$root = vfsStream::setup('root'); // <-- giving a name for root is the important part
$root = vfsStream::setup(); // <-- this is the same as above
mkdir($root->url() . '/etc');
file_put_contents($root->url() . '/etc/../test', 'test');
echo file_get_contents($root->url() . '/test');
Closing as #211 is the issue.
If you absolutely need /
as the root name "right now" you could try mockfs. It's the exact same concept as vfs, but has some key differences. The test you're trying to do here works in mockfs.
use MockFileSystem\MockFileSystem as mockfs;
mockfs::create();
mkdir('mfs:///etc'); // note the three `/`. Two are for the scheme separator, one is to designate root.
file_put_contents('mfs:///etc/../test', 'test');
echo file_get_contents('mfs:///test');
// prints "test"
MockFS is exactly what i needed. Thanks for your time and efforts.
I'm currently trying out some functionality that's normally working fine in native filesystems. But the the problem is that ../ and ./ are not working as intended. It seems ../ is not recognized as going directory back etc.
For example this is the code i tested:
I'm getting the following error:
I expect to create the file /test. But instead the file /etc/test gets created. Is this some kind of bug? I'm currently working on a Path Traversal simulation so this would be a very nice functionality to have.