Skip to content
Snippets Groups Projects
Commit becc88b1 authored by Florian Mast's avatar Florian Mast Committed by Wouter Wolters
Browse files

[BUGFIX] Solves PHP warning in FileAllowedTypesValidator

Resolves: #72890
Resolves: #73618
Releases: master, 7.6
Change-Id: Ida8a9ace681b93d1d66b0e06c893a83e549f8411
Reviewed-on: https://review.typo3.org/46787


Reviewed-by: default avatarNicole Cordes <typo3@cordes.co>
Tested-by: default avatarNicole Cordes <typo3@cordes.co>
Reviewed-by: default avatarFrank Naegler <frank.naegler@typo3.org>
Reviewed-by: default avatarRalf Zimmermann <ralf.zimmermann@tritum.de>
Tested-by: default avatarRalf Zimmermann <ralf.zimmermann@tritum.de>
Reviewed-by: default avatarJan Helke <typo3@helke.de>
Tested-by: default avatarJan Helke <typo3@helke.de>
Reviewed-by: default avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: default avatarWouter Wolters <typo3@wouterwolters.nl>
parent f8d741c9
Branches
Tags
No related merge requests found
......@@ -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
......@@ -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());
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment