diff --git a/typo3/sysext/form/Classes/Domain/Validator/FileAllowedTypesValidator.php b/typo3/sysext/form/Classes/Domain/Validator/FileAllowedTypesValidator.php index 1a10361a0c8fbbe7877e48802549fd986e23ad53..67ce42a7ca0976e142be10dc7ec21e89cc8ce72d 100755 --- a/typo3/sysext/form/Classes/Domain/Validator/FileAllowedTypesValidator.php +++ b/typo3/sysext/form/Classes/Domain/Validator/FileAllowedTypesValidator.php @@ -38,16 +38,18 @@ class FileAllowedTypesValidator extends AbstractValidator * Check if the file mime type is allowed. * * The mime type is set in the propertymapper + * * @see TYPO3\CMS\Form\Domain\Property\TypeConverter::convertFrom * - * @param mixed $value + * @param array $value * @return void */ public function isValid($value) { $allowedTypes = strtolower($this->options['types']); - $allowedMimeTypes = GeneralUtility::trimExplode(', ', $allowedTypes); - $fileMimeType = strtolower($value['type']); + $allowedMimeTypes = GeneralUtility::trimExplode(',', $allowedTypes, true); + $fileMimeType = !empty($value['type']) ? strtolower($value['type']) : ''; + if (!in_array($fileMimeType, $allowedMimeTypes, true)) { $this->addError( $this->renderMessage( @@ -69,7 +71,11 @@ class FileAllowedTypesValidator extends AbstractValidator */ public function substituteMarkers($message) { - $message = str_replace('%allowedTypes', implode(',', $this->options['types']), $message); + $allowedTypes = strtolower($this->options['types']); + $allowedMimeTypes = GeneralUtility::trimExplode(',', $allowedTypes); + $allowedTypesStringForDisplay = implode(', ', $allowedMimeTypes); + $message = str_replace('%allowedTypes', $allowedTypesStringForDisplay, $message); + return $message; } -} +} \ No newline at end of file diff --git a/typo3/sysext/form/Tests/Unit/Validator/FileAllowedTypesValidatorTest.php b/typo3/sysext/form/Tests/Unit/Validator/FileAllowedTypesValidatorTest.php index e34d3e9881a7fc6280b839fb666e9b5a780cd652..e31b41b5f1f1f713a7be838bf7716efd442088ef 100644 --- a/typo3/sysext/form/Tests/Unit/Validator/FileAllowedTypesValidatorTest.php +++ b/typo3/sysext/form/Tests/Unit/Validator/FileAllowedTypesValidatorTest.php @@ -24,20 +24,24 @@ class FileAllowedTypesValidatorTest extends AbstractValidatorTest */ protected $subjectClassName = \TYPO3\CMS\Form\Domain\Validator\FileAllowedTypesValidator::class; - protected function setUp() - { - $this->markTestSkipped('Erros found in specific implementation, see @todo remarks there'); - } - /** * @return array */ public function validTypesProvider() { return array( - 'pdf in (pdf)' => array(array('application/pdf', 'application/pdf')), - 'pdf in (pdf, json)' => array(array('application/pdf, application/json', 'application/pdf')) - + 'pdf in (pdf)' => [ + 'application/pdf', + [ + 'type' => 'application/pdf', + ], + ], + 'pdf in (pdf, json)' => [ + 'application/pdf, application/json', + [ + 'type' => 'application/pdf', + ], + ], ); } @@ -47,38 +51,64 @@ class FileAllowedTypesValidatorTest extends AbstractValidatorTest public function invalidTypesProvider() { return array( - 'xml in (pdf, json)' => array(array('application/pdf, application/json', 'application/xml')), - 'xml in (pdf)' => array(array('application/pdf, application/json', 'application/xml')) + 'xml in (pdf, json)' => [ + 'application/pdf, application/json', + [ + 'type' => 'application/xml', + ], + ], + 'xml in (pdf)' => [ + 'application/pdf', + [ + 'type' => 'application/xml', + ], + ], + 'empty mimetype' => [ + 'application/pdf, application/json', + [ + 'type' => '', + ], + ], + 'empty value' => [ + 'application/pdf, application/json', + '', + ], ); } /** * @test + * @param string $types + * @param array $value * @dataProvider validTypesProvider */ - public function validateForValidInputHasEmptyErrorResult($input) + public function validateForValidInputHasEmptyErrorResult($types, $value) { - $options = array('element' => uniqid('test'), 'errorMessage' => uniqid('error')); - $options['types'] = $input[0]; + $options = [ + 'element' => uniqid('test'), + 'errorMessage' => uniqid('error'), + 'types' => $types, + ]; $subject = $this->createSubject($options); - $this->assertEmpty( - $subject->validate($input[1])->getErrors() - ); + $this->assertEmpty($subject->validate($value)->getErrors()); } /** * @test + * @param string $types + * @param array $value * @dataProvider invalidTypesProvider */ - public function validateForInvalidInputHasNotEmptyErrorResult($input) + public function validateForInvalidInputHasNotEmptyErrorResult($types, $value) { - $options = array('element' => uniqid('test'), 'errorMessage' => uniqid('error')); - $options['types'] = $input[0]; + $options = [ + 'element' => uniqid('test'), + 'errorMessage' => uniqid('error'), + 'types' => $types, + ]; $subject = $this->createSubject($options); - $this->assertNotEmpty( - $subject->validate($input[1])->getErrors() - ); + $this->assertNotEmpty($subject->validate($value)->getErrors()); } }