[BUGFIX] Make alphanum. filter work with umlauts
authorAndreas Lappe <nd@off-pist.de>
Wed, 28 Mar 2012 16:57:15 +0000 (18:57 +0200)
committerSteffen Ritter <info@rs-websystems.de>
Sat, 13 Oct 2012 16:10:23 +0000 (18:10 +0200)
Changes the regular expression used to validate the string into a
unicode-aware character-class and adds two tests for this.

Change-Id: I93e7bce7d327e19a72ba1342fb37c3ead2f57b73
Fixes: #35284
Releases: 4.6, 4.7, 6.0
Reviewed-on: http://review.typo3.org/13931
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
typo3/sysext/form/Classes/System/Filter/Alphanumeric.php
typo3/sysext/form/Tests/Unit/System/Filter/AlphanumericTest.php [new file with mode: 0644]

index aa1ffc0..7a84ff0 100644 (file)
@@ -68,7 +68,7 @@ class tx_form_System_Filter_Alphanumeric implements tx_form_System_Filter_Interf
        public function filter($value) {
                $whiteSpace = $this->allowWhiteSpace ? '\s' : '';
 
-               $pattern = '/[^a-zA-Z0-9'  . $whiteSpace . ']/u';
+               $pattern = '/[^\pL\d' . $whiteSpace . ']/u';
 
                return preg_replace($pattern, '', (string) $value);
        }
diff --git a/typo3/sysext/form/Tests/Unit/System/Filter/AlphanumericTest.php b/typo3/sysext/form/Tests/Unit/System/Filter/AlphanumericTest.php
new file mode 100644 (file)
index 0000000..b961cab
--- /dev/null
@@ -0,0 +1,81 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
+*
+*  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.
+*
+*  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 case for class tx_form_System_Filter_Alphanumeric
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class tx_form_System_Filter_AlphanumericTest extends Tx_Extbase_BaseTestCase {
+       /**
+        * @var tx_form_System_Filter_Alphanumeric
+        */
+       protected $fixture = NULL;
+
+       public function setUp() {
+               $this->fixture = new tx_form_System_Filter_Alphanumeric();
+       }
+
+       public function tearDown() {
+               $this->fixture = NULL;
+       }
+
+       /**
+        * @test
+        */
+       public function filterForStringWithUnicodeCharactersAndSpacesReturnsInputString() {
+               $input = 'My name contains äøüößØœ';
+
+                       // This is default, but let's be explicit:
+               $this->fixture->setAllowWhiteSpace(TRUE);
+
+               $this->assertSame(
+                       $input,
+                       $this->fixture->filter($input)
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function filterForStringWithUnicodeCharactersAndSpacesWithAllowWhitespaceSetToFalseReturnsInputStringWithoutSpaces() {
+               $input = 'My name contains äøüößØœ';
+               $expected = 'MynamecontainsäøüößØœ';
+
+               $this->fixture->setAllowWhiteSpace(FALSE);
+
+               $this->assertSame($expected, $this->fixture->filter($input));
+       }
+
+       /**
+        * @test
+        */
+       public function filterAllowsNumericCharacters() {
+               $this->assertSame('foo23bar', $this->fixture->filter('foo23bar'));
+       }
+}
+?>
\ No newline at end of file