[BUGFIX] DataHandler: cast value to string in checkValueForInput() 60/42260/3
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Tue, 4 Aug 2015 16:31:50 +0000 (18:31 +0200)
committerFrank Nägler <frank.naegler@typo3.org>
Wed, 5 Aug 2015 21:31:34 +0000 (23:31 +0200)
Explicitly cast the value as a string before using substr() on it.
Otherwise NULL values would be passed to substr(), resulting in a return
value of FALSE. Without MySQL strict mode this has no direct influence
on the further usage of the value as string as the string representation
of FALSE is an empty string. With MySQL strict mode enabled this leads
to errors upon insertion of records into the database as boolean values
get converted to 0/1 respectively.

Resolves: #68602
Related: #68562
Related: #55082
Releases: master
Change-Id: Idc3ffa147965083492a04b12c64a6c15ddd2277b
Reviewed-on: http://review.typo3.org/42260
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php

index cce2f12..c3f9adf 100644 (file)
@@ -1804,7 +1804,7 @@ class DataHandler {
                }
                // Secures the string-length to be less than max.
                if ((int)$tcaFieldConf['max'] > 0) {
-                       $value = $GLOBALS['LANG']->csConvObj->substr($GLOBALS['LANG']->charSet, $value, 0, (int)$tcaFieldConf['max']);
+                       $value = $GLOBALS['LANG']->csConvObj->substr($GLOBALS['LANG']->charSet, (string)$value, 0, (int)$tcaFieldConf['max']);
                }
                // Checking range of value:
                if ($tcaFieldConf['range'] && $value != $tcaFieldConf['checkbox'] && (int)$value !== (int)$tcaFieldConf['default']) {
index cb8fabe..6630df3 100644 (file)
@@ -763,4 +763,16 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->assertSame($expectedResult, $this->subject->_call('checkValueForCheck', $result, $value, $tcaFieldConfiguration, '', 0, 0, ''));
        }
 
+       /**
+        * @test
+        */
+       public function checkValueForInputConvertsNullToEmptyString() {
+               $previousLanguageService = $GLOBALS['LANG'];
+               $GLOBALS['LANG'] = GeneralUtility::makeInstance(\TYPO3\CMS\Lang\LanguageService::class);
+               $GLOBALS['LANG']->init('default');
+               $expectedResult = array('value' => '');
+               $this->assertSame($expectedResult, $this->subject->_call('checkValueForInput', NULL, array('type' => 'string', 'max' => 40), 'tt_content', 'NEW55c0e67f8f4d32.04974534', 89, 'table_caption'));
+               $GLOBALS['LANG'] = $previousLanguageService;
+       }
+
 }