Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileNotFoundException with sanitize_chars in directory name #18

Closed
martinwang2002 opened this issue Jun 19, 2021 · 5 comments
Closed

FileNotFoundException with sanitize_chars in directory name #18

martinwang2002 opened this issue Jun 19, 2021 · 5 comments

Comments

@martinwang2002
Copy link

FileNotFoundException will raise if sanitize_chars exist in directory name

Sample path to reproduce

$remote_filepath = '[test]test/test.txt';

I have passed sanitize_chars without [ and ] in options of Masbug\Flysystem\GoogleDriveAdapter, but doesn't help.

Logs League\Flysystem\FileNotFoundException

File not found at path: [test]test

at \vendor\masbug\flysystem-google-drive-ext\src\GoogleDriveAdapter.php:1773
1769▕ if($makeFullVirtualPath)
1770▕ return $this->makeFullVirtualPath($displayPath, $returnFirstItem);
1771▕
1772▕ if(empty($this->cachedPaths[$displayPath]))
➜ 1773▕ throw new FileNotFoundException($displayPath);
1774▕
1775▕ return $this->returnSingle($this->cachedPaths[$displayPath], $returnFirstItem);
1776▕ }
1777▕

1 \vendor\masbug\flysystem-google-drive-ext\src\GoogleDriveAdapter.php:1824
Masbug\Flysystem\GoogleDriveAdapter::toVirtualPath("[test]test")

2 \vendor\masbug\flysystem-google-drive-ext\src\GoogleDriveAdapter.php:297
Masbug\Flysystem\GoogleDriveAdapter::toSingleVirtualPath("[test]test")

@erikn69
Copy link
Contributor

erikn69 commented Jun 25, 2021

@martinwang2002 Did you try the last unreleased changes on flysystem-google-drive-ext 1.x,
i believe that bug is already fixed by me

public function testWritingReadingFilesWithSpecialPath()
{
$adapter = $this->adapter();
foreach ([
'a path with square brackets in filename 1' => 'some/file[name].txt',
'a path with square brackets in filename 2' => 'some/file[0].txt',
'a path with square brackets in filename 3' => 'some/file[10].txt',
'a path with square brackets in dirname 1' => 'some[name]/file.txt',
'a path with square brackets in dirname 2' => 'some[0]/file.txt',
'a path with square brackets in dirname 3' => 'some[10]/file.txt',
'a path with curly brackets in filename 1' => 'some/file{name}.txt',
'a path with curly brackets in filename 2' => 'some/file{0}.txt',
'a path with curly brackets in filename 3' => 'some/file{10}.txt',
'a path with curly brackets in dirname 1' => 'some{name}/filename.txt',
'a path with curly brackets in dirname 2' => 'some{0}/filename.txt',
'a path with curly brackets in dirname 3' => 'some{10}/filename.txt',
'a path with space in dirname' => 'some dir/filename.txt',
'a path with space in filename' => 'somedir/file name.txt'
] as $msg => $path) {
$adapter->write($path, 'contents', new Config());
$contents = $adapter->read($path);
$this->assertEquals('contents', isset($contents['contents']) ? $contents['contents'] : '', $msg);
}
}

Give a try please, @masbug if works on this test, maybe he needs a new release, also there is'nt v2's release

@erikn69
Copy link
Contributor

erikn69 commented Jun 25, 2021

I run '[test]test/test.txt' on testing

public function testWritingReadingFilesWithSpecialPath()
    {
        $adapter = $this->adapter();
        foreach ([
            'a path with square brackets in dirname 2' => '[test]test/test.txt',
        ] as $msg => $path) {
            $adapter->write($path, 'contents', new Config());
            $contents = $adapter->read($path);

            $this->assertEquals('contents', isset($contents['contents']) ? $contents['contents'] : '', $msg);
        }
 }

I get

PHPUnit 9.5.6 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.0.5
Configuration: google_flysystem\phpunit.xml.dist

.                                                                   1 / 1 (100%)

Time: 00:05.495, Memory: 8.00 MB

OK (1 test, 1 assertion)

image

@martinwang2002
Copy link
Author

Great! I have tested and it works. I got this package via packagist, so a new version is preferred.

@erikn69
Copy link
Contributor

erikn69 commented Jul 5, 2021

@masbug I have fixed some common bugs, and i made it works as expected behavior according v1 and v2 flysystem docs, so, when would the new release date be?

@masbug
Copy link
Owner

masbug commented Jul 13, 2021

@erikn69 Sorry for my tardiness. Thank you for the great work you've done so far! I tagged the releases for both branches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants