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

File#filterFilename does not use FolderNameFilter #419

Open
sb-relaxt-at opened this issue Sep 4, 2020 · 2 comments
Open

File#filterFilename does not use FolderNameFilter #419

sb-relaxt-at opened this issue Sep 4, 2020 · 2 comments

Comments

@sb-relaxt-at
Copy link

From my understanding the named method should use a FolderNameFilter when sanitizing the path (except for the last part if this is a file). But it uses a FileNameFilter for all parts of the path. Therefore a path like foo.bar/example.jpg will remain foo.bar/example.jpg although it should be (and will be later converted to) foo-bar/example.jpg

@sb-relaxt-at
Copy link
Author

Something like this should work as getFilter() is overwritten in Folder to return a FolderNameFilter:

protected function filterFilename($name)
{
    // Fix illegal characters
    $filter = $this->getFilter();
    $folderFileFilter = FolderNameFilter::create();
    $parts = array_filter(preg_split("#[/\\\\]+#", $name));

    return implode('/', array_merge(
        array_map(function ($part) use ($folderFileFilter) {
            return $folderFileFilter->filter($part);
        }, array_slice($parts, 0, -1)),
        array_map(function ($part) use ($filter) {
            return $filter->filter($part);
        }, array_slice($parts, -1, 1))
    ));
}

@emteknetnz
Copy link
Member

Do you know if this is causing any issues in the cms or on a website front end?

Would you like to raise a PR to fix this?

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

No branches or pull requests

2 participants