[BUGFIX] Remove dependency to iconv lib in form
authorHelmut Hummel <helmut.hummel@typo3.org>
Wed, 14 Nov 2012 23:49:15 +0000 (00:49 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Wed, 14 Nov 2012 23:51:27 +0000 (00:51 +0100)
The form extension uses iconv_strlen to determine
the string length, which fails when this method
is not present in PHP.

Use the CharsetConverter class instead.

Fixes: #42990
Releases: 6.0

Change-Id: Ibf7e82c85bd808f036c7d0715f55d6f1f9e5b8d5
Reviewed-on: http://review.typo3.org/16449
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/form/Classes/Validation/AbstractValidator.php
typo3/sysext/form/Classes/Validation/LengthValidator.php
typo3/sysext/form/Tests/Unit/Validation/LengthValidatorTest.php

index 1cd4e61..ded6ec4 100644 (file)
@@ -101,7 +101,6 @@ abstract class AbstractValidator implements \TYPO3\CMS\Form\Validation\Validator
         * Constructor
         *
         * @param array $arguments Typoscript configuration for the validation rule
-        * @return void
         */
        public function __construct($arguments) {
                $this->localCobj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
index 11b1d2b..1ad211f 100644 (file)
@@ -47,12 +47,20 @@ class LengthValidator extends \TYPO3\CMS\Form\Validation\AbstractValidator {
        protected $maximum;
 
        /**
+        * TYPO3 charset encoding object
+        *
+        * @var \TYPO3\CMS\Core\Charset\CharsetConverter
+        */
+       protected $charsetConverter = NULL;
+
+       /**
         * Constructor
         *
         * @param array $arguments Typoscript configuration
         * @return void
         */
        public function __construct($arguments) {
+               $this->charsetConverter = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Charset\\CharsetConverter');
                $this->setMinimum($arguments['minimum'])->setMaximum($arguments['maximum']);
                parent::__construct($arguments);
        }
@@ -66,7 +74,7 @@ class LengthValidator extends \TYPO3\CMS\Form\Validation\AbstractValidator {
        public function isValid() {
                if ($this->requestHandler->has($this->fieldName)) {
                        $value = $this->requestHandler->getByMethod($this->fieldName);
-                       $length = iconv_strlen($value);
+                       $length = $this->charsetConverter->strlen('utf-8', $value);
                        if ($length < $this->minimum) {
                                return FALSE;
                        }
index 146c9e3..288b286 100644 (file)
@@ -53,8 +53,8 @@ class LengthValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        public function validLengthProvider() {
                return array(
-                       '4 ≤ length(myString) ≤ 8' => array(array(4, 8, 'myString')),
-                       '8 ≤ length(myString) ≤ 8' => array(array(8, 8, 'myString')),
+                       '4 ≤ length(myString) ≤ 8' => array(array(4, 8, 'mäString')),
+                       '8 ≤ length(myString) ≤ 8' => array(array(8, 8, 'möString')),
                        '4 ≤ length(myString)'       => array(array(4, NULL, 'myString')),
                        '4 ≤ length(asdf) ≤ 4'     => array(array(4, 4, 'asdf')),
                );