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

FolderNameFilter needs multiple calls in order to fully filter certain patterns #418

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

Comments

@sb-relaxt-at
Copy link

Tested using silverstripe/assets v1.6.1:

$folderFilter = new SilverStripe\Assets\FolderNameFilter();
$folderFilter->filter('foo.-bar'); // foo--bar
$folderFilter->filter('foo--bar'); // foo-bar

I assume this is due to the merge order of the replacement pattern config. From my point of view it would be better to perform replacements until the name is stable as there might be complex dependencies between patterns that require multiple passes. Something like this should work in FileNameFilter#filter:

$nameBefore = null;
while($nameBefore !== $name) {
    $nameBefore = $name;
    foreach ($this->getReplacements() as $regex => $replace) {
        $name = preg_replace($regex, $replace, $name);
    }
}
@emteknetnz
Copy link
Member

Related #419

Would you like to raise a PR to fix this?

@sb-relaxt-at
Copy link
Author

I finally prepared a PR. Which branch should I create the pull request against?

@michalkleiner
Copy link
Contributor

1.12 @sb-relaxt-at, thanks!

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

3 participants