[BUGFIX] Exception on modifying page properties
authorOliver Hader <oliver@typo3.org>
Sat, 16 Jun 2012 13:23:12 +0000 (15:23 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Sat, 16 Jun 2012 13:44:10 +0000 (15:44 +0200)
An exception "#1300096564: uid of file has to be numeric" is
thrown on modifying and saving the properties of a pages record.
It's required that there are zero file elements on that page,
thus the FAL filter gets an faulty array which is not sanitized
before trying to get an accordant file.

Change-Id: I236610cebe872bcd3a4e49ceec4b24a26b2ef63b
Fixes: #38114
Releases: 6.0
Reviewed-on: http://review.typo3.org/12128
Reviewed-by: Georg Ringer
Tested-by: Georg Ringer
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
t3lib/class.t3lib_tcemain.php
t3lib/file/Utility/FileExtensionFilter.php
tests/Unit/t3lib/file/Utility/FileExtensionFilterTest.php [new file with mode: 0644]

index 999ff4b..210bcfe 100644 (file)
@@ -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;
                        }
 
index a63a1a6..d4eba06 100644 (file)
@@ -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 (file)
index 0000000..90ce50f
--- /dev/null
@@ -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