From a5580a21feac8c8e672b0d19bb8af51d886f4d4a Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 18 Jan 2024 16:57:15 +1300 Subject: [PATCH] FIX Pass variant args into array_merge correctly Without this, trying to pass any variant name into variantParts() will result in `TypeError: array_merge(): Argument #2 must be of type array, string given` This wasn't caught until now because `variantParts()` isn't actually used anywhere in our codebase. --- src/ImageManipulation.php | 2 +- tests/php/ImageTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ImageManipulation.php b/src/ImageManipulation.php index 02825acb..b53c4926 100644 --- a/src/ImageManipulation.php +++ b/src/ImageManipulation.php @@ -1039,7 +1039,7 @@ public function variantParts($variantName) throw new InvalidArgumentException('Invalid variant name arguments: ' . $variantName); } - return array_merge([$matches['format']], $args[0]); + return array_merge([$matches['format']], $args); } /** diff --git a/tests/php/ImageTest.php b/tests/php/ImageTest.php index c44da35d..8eb8d928 100644 --- a/tests/php/ImageTest.php +++ b/tests/php/ImageTest.php @@ -419,7 +419,7 @@ public function testVariantParts() $image = singleton(Image::class); $format = 'Pad'; $args = [331, 313, '222222', 0]; - $name = $image->variantName($format, $args); + $name = $image->variantName($format, ...$args); $this->assertEquals( array_merge([$format], $args), $image->variantParts($name) @@ -432,7 +432,7 @@ public function testVariantPartsThrowsOnInvalidName() /** @var Image $image */ $image = singleton(Image::class); $args = ['foo']; - $name = $image->variantName('Invalid', $args); + $name = $image->variantName('Invalid', ...$args); $image->variantParts($name); }