[BUGFIX] Use mb_strlen in StringLengthValidator 93/51593/3
authorGeorg Ringer <georg.ringer@gmail.com>
Wed, 8 Feb 2017 18:59:28 +0000 (19:59 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Thu, 9 Feb 2017 08:21:57 +0000 (09:21 +0100)
By using mb_strlen for checking the length, the
check counts multibyte values now correctly.

Resolves: #79684
Releases: master
Change-Id: Idcc9fc6e77d0cd42bc43986acb956af67da2453d
Reviewed-on: https://review.typo3.org/51593
Reviewed-by: Stephan Großberndt <stephan@grossberndt.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org>
Tested-by: Philipp Gampe <philipp.gampe@typo3.org>
Reviewed-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Tested-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/extbase/Classes/Validation/Validator/StringLengthValidator.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/StringLengthValidatorTest.php

index c249773..68fd428 100644 (file)
@@ -55,8 +55,7 @@ class StringLengthValidator extends AbstractValidator
             return;
         }
 
-        // @todo Use \TYPO3\CMS\Core\Charset\CharsetConverter::strlen() instead; How do we get the charset?
-        $stringLength = strlen($value);
+        $stringLength = mb_strlen($value, 'utf-8');
         $isValid = true;
         if ($stringLength < $this->options['minimum']) {
             $isValid = false;
index fcb7368..30cb907 100644 (file)
@@ -268,8 +268,11 @@ class StringLengthValidatorTest extends \TYPO3\Components\TestingFramework\Core\
      */
     public function validateRegardsMultibyteStringsCorrectly()
     {
-        //             $this->validatorOptions(array('maximum' => 8));
-//             $this->assertFalse($this->validator->validate('überlang')->hasErrors());
-        $this->markTestSkipped('Validator needs to be adjusted regarding multibyte char lengths.');
+        $options = ['minimum' => 0, 'maximum' => 8];
+        $validator = $this->getMockBuilder($this->validatorClassName)
+            ->setMethods(['dummy'])
+            ->setConstructorArgs([$options])
+            ->getMock();
+        $this->assertFalse($validator->validate('überlang')->hasErrors());
     }
 }