Skip to content

Commit

Permalink
FIX Pass variant args into array_merge correctly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
GuySartorelli committed Jan 25, 2024
1 parent e46e8b0 commit c8f0c29
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ImageManipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/php/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}

Expand Down

0 comments on commit c8f0c29

Please sign in to comment.