[BUGFIX] Make alphabetic filter work with umlauts
authorAndreas Lappe <nd@off-pist.de>
Wed, 28 Mar 2012 17:01:20 +0000 (19:01 +0200)
committerAndreas Wolf <andreas.wolf@ikt-werk.de>
Sun, 1 Apr 2012 10:40:37 +0000 (12:40 +0200)
Changes the regular expression used to validate the string into a
unicode-aware character-class and adds two testcases for this.

Change-Id: I247437d9e722c4656ddab0dd2e2ef6a960837cff
Fixes: #35296
Releases: 4.5, 4.7, 6.0
Reviewed-on: http://review.typo3.org/10066
Reviewed-by: Andreas Wolf
Tested-by: Andreas Wolf
typo3/sysext/form/Classes/System/Filter/Alphabetic.php
typo3/sysext/form/Tests/Unit/System/Filter/AlphabeticTest.php [new file with mode: 0644]

index 5f36b4c..0c5e273 100644 (file)
@@ -68,7 +68,7 @@ class tx_form_System_Filter_Alphabetic implements tx_form_System_Filter_Interfac
        public function filter($value) {
                $whiteSpace = $this->allowWhiteSpace ? '\s' : '';
 
-               $pattern = '/[^a-zA-Z'  . $whiteSpace . ']/u';
+               $pattern = '/[^[:alpha:]' . $whiteSpace . ']/u';
 
                return preg_replace($pattern, '', (string) $value);
        }
diff --git a/typo3/sysext/form/Tests/Unit/System/Filter/AlphabeticTest.php b/typo3/sysext/form/Tests/Unit/System/Filter/AlphabeticTest.php
new file mode 100644 (file)
index 0000000..b4632f2
--- /dev/null
@@ -0,0 +1,77 @@
+<?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_Alphabetic.
+ *
+ * @author Andreas Lappe <a.lappe@kuehlhaus.com>
+ * @package TYPO3
+ * @subpackage form
+ */
+class tx_form_System_Filter_AlphabeticTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+       /**
+        * @var tx_form_System_Filter_Alphabetic
+        */
+       protected $fixture;
+
+       public function setUp() {
+               $this->fixture = new tx_form_System_Filter_Alphabetic();
+       }
+
+       public function tearDown() {
+               unset($this->fixture);
+       }
+
+       /**
+        * @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 äøüößØœ';
+               $inputWithoutSpaces = 'MynamecontainsäøüößØœ';
+
+               $this->fixture->setAllowWhiteSpace(FALSE);
+
+               $this->assertSame(
+                       $inputWithoutSpaces,
+                       $this->fixture->filter($input)
+               );
+       }
+}
+?>
\ No newline at end of file