[BUGFIX] Make AlphanumericValidator work with umlauts
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Fri, 4 Jan 2013 17:14:45 +0000 (18:14 +0100)
committerTymoteusz Motylewski <t.motylewski@gmail.com>
Sat, 5 Jan 2013 14:27:17 +0000 (15:27 +0100)
Changes the regular expression used to validate the
string into a unicode-aware character-class and adds
a tests for this.

Backport of: https://review.typo3.org/#/c/9923/

Releases: 6.1, 6.0
Fixes: #44216
Change-Id: I85b77691ed7eea04972d834bb5fd083555872eee
Reviewed-on: https://review.typo3.org/17370
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Stefan Froemken
Tested-by: Stefan Froemken
Reviewed-by: Tymoteusz Motylewski
Tested-by: Tymoteusz Motylewski
typo3/sysext/extbase/Classes/Validation/Validator/AlphanumericValidator.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/AlphanumericValidatorTest.php

index 562592f..345d695 100644 (file)
@@ -43,11 +43,12 @@ class AlphanumericValidator extends \TYPO3\CMS\Extbase\Validation\Validator\Abst
         */
        public function isValid($value) {
                $this->errors = array();
-               if (is_string($value) && preg_match('/^[a-z0-9]*$/i', $value)) {
-                       return TRUE;
+               if (!is_string($value) || preg_match('/^[[:alnum:]]*$/u', $value) !== 1) {
+                       $this->addError('The given subject was not a valid alphanumeric string.', 1221551320);
+                       return FALSE;
                }
-               $this->addError('The given subject was not a valid alphanumeric string.', 1221551320);
-               return FALSE;
+
+               return TRUE;
        }
 }
 
index 259b79d..a0b3317 100644 (file)
@@ -54,6 +54,14 @@ class AlphanumericValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\Validation
        public function alphanumericValidatorCreatesTheCorrectErrorForAnInvalidSubject() {
                $this->assertEquals(1, count($this->validator->validate('adsf%&/$jklsfdö')->getErrors()));
        }
+
+       /**
+        * @test
+        * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
+        */
+       public function alphanumericValidatorShouldReturnNoErrorsForAnAlphanumericUnicodeString() {
+               $this->assertFalse($this->validator->validate('12ssDF34daweidfäøüößØœ你好')->hasErrors());
+       }
 }
 
 ?>
\ No newline at end of file