Found in 5.x-dev but presumably has been around since 4.0
Description
The ImageManipulation::variantParts() throws an exception for some valid variants, such as FitMax variants.
This is the case for any variant which has another variant method name as part of it. For example, Fit variants work, but FitMax variants do not.
How to reproduce
The following code will die on line 4 with InvalidArgumentException: Invalid variant name arguments: FitMaxWzEwMCwyMDBd
use SilverStripe\Assets\File;
$imageManip = new File();
$name = $imageManip->variantName('FitMax', '100', '200');
$parts = $imageManip->variantParts($name);
Possible Solution
Possibly sorting the array of methods in alphabetical descending order before using it in the regex could work, though that feels pretty flaky - and would still potentially incorrectly think a Fit variant is actually a FitMax variant if the base64 component starts with Max (though I'm not sure there's anything we can do about that edge case).
More robust (but more complex - probably just go with the first option) would be to find all combinations of methods like this, and then instead of writing the regex like (Fit|FitMax|AnotherMethod), we'd have (Fit(Max)?)|AnotherMethod)
Additional Context
No response
Validations
[X] Check that there isn't already an issue that reports the same bug
[X] Double check that your reproduction steps work in a fresh installation of silverstripe/installer (with any code examples you've provided)
Module version(s) affected
Found in 5.x-dev but presumably has been around since 4.0
Description
The
ImageManipulation::variantParts()
throws an exception for some valid variants, such asFitMax
variants.This is the case for any variant which has another variant method name as part of it. For example,
Fit
variants work, butFitMax
variants do not.How to reproduce
The following code will die on line 4 with
InvalidArgumentException: Invalid variant name arguments: FitMaxWzEwMCwyMDBd
Possible Solution
Possibly sorting the array of methods in alphabetical descending order before using it in the regex could work, though that feels pretty flaky - and would still potentially incorrectly think a
Fit
variant is actually aFitMax
variant if the base64 component starts withMax
(though I'm not sure there's anything we can do about that edge case).More robust (but more complex - probably just go with the first option) would be to find all combinations of methods like this, and then instead of writing the regex like
(Fit|FitMax|AnotherMethod)
, we'd have(Fit(Max)?)|AnotherMethod)
Additional Context
No response
Validations
silverstripe/installer
(with any code examples you've provided)