Skip to content

Commit

Permalink
Fix bug when trying to create FileExtension
Browse files Browse the repository at this point in the history
Creation was only possible from lowercase extensions. This patch makes
it possible to create from lowercase or uppercase.
  • Loading branch information
olivervogel committed Jan 17, 2025
1 parent f701421 commit 0cd29e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Encoders/FileExtensionEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function encoderByFileExtension(null|string|FileExtension $extension):
}

try {
$extension = is_string($extension) ? FileExtension::from($extension) : $extension;
$extension = is_string($extension) ? FileExtension::from(strtolower($extension)) : $extension;
} catch (Error) {
throw new EncoderException('No encoder found for file extension (' . $extension . ').');
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Unit/Encoders/FileExtensionEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ public static function targetEncoderProvider(): Generator
yield ['tif', TiffEncoder::class];
yield ['jp2', Jpeg2000Encoder::class];
yield ['heic', HeicEncoder::class];
yield ['WEBP', WebpEncoder::class];
yield ['AVIF', AvifEncoder::class];
yield ['JPEG', JpegEncoder::class];
yield ['JPG', JpegEncoder::class];
yield ['BMP', BmpEncoder::class];
yield ['GIF', GifEncoder::class];
yield ['PNG', PngEncoder::class];
yield ['TIFF', TiffEncoder::class];
yield ['TIF', TiffEncoder::class];
yield ['JP2', Jpeg2000Encoder::class];
yield ['HEIC', HeicEncoder::class];
yield [FileExtension::WEBP, WebpEncoder::class];
yield [FileExtension::AVIF, AvifEncoder::class];
yield [FileExtension::JPG, JpegEncoder::class];
Expand Down

0 comments on commit 0cd29e6

Please sign in to comment.