diff --git a/typo3/sysext/filelist/Classes/Matcher/ResourceFileExtensionMatcher.php b/typo3/sysext/filelist/Classes/Matcher/ResourceFileExtensionMatcher.php index be9552d001eb002667d1671a3f91c66cfed96476..0fa3004c01d0c3fbfb72a366a1b8f4aec1137c42 100644 --- a/typo3/sysext/filelist/Classes/Matcher/ResourceFileExtensionMatcher.php +++ b/typo3/sysext/filelist/Classes/Matcher/ResourceFileExtensionMatcher.php @@ -39,14 +39,14 @@ class ResourceFileExtensionMatcher implements MatcherInterface */ public function setExtensions(array $extensions): self { - $this->extensions = $extensions; + $this->extensions = array_map(strtolower(...), $extensions); return $this; } public function addExtension(string $extension): self { - $this->extensions[] = $extension; + $this->extensions[] = strtolower($extension); return $this; } @@ -56,14 +56,14 @@ class ResourceFileExtensionMatcher implements MatcherInterface */ public function setIgnoredExtensions(array $ignoredExtensions): self { - $this->ignoredExtensions = $ignoredExtensions; + $this->ignoredExtensions = array_map(strtolower(...), $ignoredExtensions); return $this; } public function addIgnoredExtension(string $ignoredExtension): self { - $this->ignoredExtensions[] = $ignoredExtension; + $this->ignoredExtensions[] = strtolower($ignoredExtension); return $this; } @@ -79,11 +79,11 @@ class ResourceFileExtensionMatcher implements MatcherInterface return false; } - if (in_array($item->getExtension(), $this->ignoredExtensions)) { + if (in_array($item->getExtension(), $this->ignoredExtensions, true)) { return false; } - if (in_array('*', $this->extensions) || in_array($item->getExtension(), $this->extensions)) { + if (in_array('*', $this->extensions, true) || in_array($item->getExtension(), $this->extensions, true)) { return true; } diff --git a/typo3/sysext/filelist/Tests/Unit/Matcher/ResourceFileExtensionMatcherTest.php b/typo3/sysext/filelist/Tests/Unit/Matcher/ResourceFileExtensionMatcherTest.php new file mode 100644 index 0000000000000000000000000000000000000000..972de9a2685bd8a722c335af93ff2398c5cd877b --- /dev/null +++ b/typo3/sysext/filelist/Tests/Unit/Matcher/ResourceFileExtensionMatcherTest.php @@ -0,0 +1,77 @@ +<?php + +declare(strict_types=1); + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +namespace TYPO3\CMS\Filelist\Tests\Unit\Matcher; + +use TYPO3\CMS\Core\Resource\File; +use TYPO3\CMS\Core\Resource\ResourceStorage; +use TYPO3\CMS\Filelist\Matcher\ResourceFileExtensionMatcher; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; + +final class ResourceFileExtensionMatcherTest extends UnitTestCase +{ + protected ResourceStorage $storage; + + protected function setUp(): void + { + parent::setUp(); + $this->storage = $this->getMockBuilder(ResourceStorage::class)->disableOriginalConstructor()->getMock(); + } + + /** + * @test + */ + public function fileExtensionsAreTransformedToLowercase(): void + { + $matcher = new ResourceFileExtensionMatcher(); + + self::assertFalse($matcher->match($this->getFile('jpg'))); + self::assertFalse($matcher->match($this->getFile('gif'))); + $matcher->setExtensions(['JPG', 'GIF']); + self::assertTrue($matcher->match($this->getFile('jpg'))); + self::assertTrue($matcher->match($this->getFile('gif'))); + + self::assertFalse($matcher->match($this->getFile('png'))); + $matcher->addExtension('PNG'); + self::assertTrue($matcher->match($this->getFile('png'))); + } + + /** + * @test + */ + public function ignoredFileExtensionsAreTransformedToLowercase(): void + { + $matcher = new ResourceFileExtensionMatcher(); + $matcher->setExtensions(['jpg', 'gif', 'png']); + + self::assertTrue($matcher->match($this->getFile('jpg'))); + self::assertTrue($matcher->match($this->getFile('gif'))); + self::assertTrue($matcher->match($this->getFile('png'))); + + $matcher->setIgnoredExtensions(['JPG', 'GIF']); + self::assertFalse($matcher->match($this->getFile('jpg'))); + self::assertFalse($matcher->match($this->getFile('gif'))); + + $matcher->addIgnoredExtension('PNG'); + self::assertFalse($matcher->match($this->getFile('png'))); + } + + protected function getFile(string $extension): File + { + return new File(['identifier' => $extension . '-file', 'name' => 'file.' . $extension], $this->storage); + } +}