diff --git a/t3lib/class.t3lib_tcemain.php b/t3lib/class.t3lib_tcemain.php index 999ff4b98525fadd677ccea1dac34d0b8e0d760f..210bcfeedaf99488d56089db06ac41c0a605f3d9 100644 --- a/t3lib/class.t3lib_tcemain.php +++ b/t3lib/class.t3lib_tcemain.php @@ -1466,12 +1466,12 @@ class t3lib_TCEmain { * @throws RuntimeException */ protected function applyFiltersToValues(array $tcaFieldConfiguration, array $values) { - if (!is_array($tcaFieldConfiguration['filter'])) { + if (empty($tcaFieldConfiguration['filter']) || !is_array($tcaFieldConfiguration['filter'])) { return $values; } foreach ($tcaFieldConfiguration['filter'] as $filter) { - if (!$filter['userFunc']) { + if (empty($filter['userFunc'])) { continue; } diff --git a/t3lib/file/Utility/FileExtensionFilter.php b/t3lib/file/Utility/FileExtensionFilter.php index a63a1a65b64b0e66a27b1c29f44eebc2197345cf..d4eba0603d42227be62a50735a4c000f90cce006 100644 --- a/t3lib/file/Utility/FileExtensionFilter.php +++ b/t3lib/file/Utility/FileExtensionFilter.php @@ -51,11 +51,11 @@ class t3lib_file_Utility_FileExtensionFilter { /** * Entry method for use as TCEMain "inline" field filter * - * @param $parameters - * @param $tceMain + * @param array $parameters + * @param t3lib_TCEmain $tceMain * @return array */ - public function filterInlineChildren($parameters, t3lib_TCEmain $tceMain) { + public function filterInlineChildren(array $parameters, t3lib_TCEmain $tceMain) { $values = $parameters['values']; if ($parameters['allowedFileExtensions']) { @@ -69,13 +69,15 @@ class t3lib_file_Utility_FileExtensionFilter { $cleanValues = array(); foreach ($values as $value) { - $parts = t3lib_div::revExplode('_', $value, 2); - $fileReferenceUid = $parts[count($parts)-1]; + if (empty($value)) { + continue; + } - $fileReferenceRecord = t3lib_BEfunc::getRecord('sys_file_reference', $fileReferenceUid); - $fileUid = $fileReferenceRecord['uid_local']; + $parts = t3lib_div::revExplode('_', $value, 2); + $fileReferenceUid = $parts[count($parts) - 1]; - $file = t3lib_file_Factory::getInstance()->getFileObject($fileUid); + $fileReference = t3lib_file_Factory::getInstance()->getFileReferenceObject($fileReferenceUid); + $file = $fileReference->getOriginalFile(); if ($this->isAllowed($file)) { $cleanValues[] = $value; @@ -125,7 +127,7 @@ class t3lib_file_Utility_FileExtensionFilter { * Checks whether a file is allowed according to the criteria defined in the class variables ($this->allowedFileExtensions etc.) * * @param t3lib_file_FileInterface $file - * @return bool + * @return boolean */ protected function isAllowed(t3lib_file_FileInterface $file) { $result = TRUE; @@ -139,7 +141,6 @@ class t3lib_file_Utility_FileExtensionFilter { // Check disallowed file extensions if ($this->disallowedFileExtensions !== NULL && count($this->disallowedFileExtensions) > 0 && in_array($fileExt, $this->disallowedFileExtensions)) { - $result = FALSE; } diff --git a/tests/Unit/t3lib/file/Utility/FileExtensionFilterTest.php b/tests/Unit/t3lib/file/Utility/FileExtensionFilterTest.php new file mode 100644 index 0000000000000000000000000000000000000000..90ce50f62def1f5bc58769eb97dd62f6c85c2cad --- /dev/null +++ b/tests/Unit/t3lib/file/Utility/FileExtensionFilterTest.php @@ -0,0 +1,99 @@ +<?php +/*************************************************************** + * Copyright notice + * + * (c) 2012 Oliver Hader <oliver.hader@typo3.org> + * All rights reserved + * + * This script is part of the TYPO3 project. The TYPO3 project is + * free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * The GNU General Public License can be found at + * http://www.gnu.org/copyleft/gpl.html. + * A copy is found in the textfile GPL.txt and important notices to the license + * from the author is found in LICENSE.txt distributed with these scripts. + * + * + * This script is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * This copyright notice MUST APPEAR in all copies of the script! + ***************************************************************/ + +/** + * Test suite for filtering files by their extensions. + * + * @author Oliver Hader <oliver.hader@typo3.org> + * @package TYPO3 + * @subpackage t3lib + */ +class t3lib_file_Utility_FileExtensionFilterTest extends Tx_Phpunit_TestCase { + /** + * @var t3lib_file_Utility_FileExtensionFilter + */ + protected $filter; + + /** + * @var array + */ + protected $parameters; + + /** + * @var t3lib_TCEmain|PHPUnit_Framework_MockObject_MockObject + */ + protected $tceMainMock; + + /** + * Sets up this test suite. + */ + protected function setUp() { + $this->filter = new t3lib_file_Utility_FileExtensionFilter(); + $this->tceMainMock = $this->getMock('t3lib_TCEmain', array('deleteAction'), array()); + } + + /** + * Cleans up this test suite. + */ + protected function tearDown() { + unset($this->tceMainMock); + unset($this->parameters); + unset($this->filter); + } + + /** + * @param array|string $allowed + * @param array|string $disallowed + * @param array|string $values + * + * @test + * @dataProvider invalidInlineChildrenFilterParametersDataProvider + */ + public function areInlineChildrenFilteredWithInvalidParameters($allowed, $disallowed, $values) { + $this->parameters = array( + 'allowedFileExtensions' => $allowed, + 'disallowedFileExtensions' => $disallowed, + 'values' => $values, + ); + + $this->tceMainMock->expects($this->never())->method('deleteAction'); + $this->filter->filterInlineChildren($this->parameters, $this->tceMainMock); + } + + /** + * @return array + */ + public function invalidInlineChildrenFilterParametersDataProvider() { + return array( + array('', '', array(0, 1, 3, 4)), + array(NULL, NULL, NULL), + array(NULL, NULL, array('', NULL, FALSE)), + ); + } +} + +?> \ No newline at end of file