[BUGFIX] Handle utf8 strings in TitleCaseFilter 40/33340/2
authorGraeme Worthy <graeme@workben.ch>
Thu, 16 Oct 2014 10:50:44 +0000 (12:50 +0200)
committerPhilipp Gampe <philipp.gampe@typo3.org>
Thu, 16 Oct 2014 20:44:58 +0000 (22:44 +0200)
Use proper charset aware string conversion API to handle
the value given to the TitleCaseFilter.

Resolves: #62279
Releases: master, 6.2
Change-Id: I500af9f1fb6769ea35197e19b2a0a7876d7eb736
Reviewed-on: http://review.typo3.org/33340
Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org>
Tested-by: Philipp Gampe <philipp.gampe@typo3.org>
typo3/sysext/form/Classes/Filter/TitleCaseFilter.php
typo3/sysext/form/Tests/Unit/Filter/TitleCaseFilterTest.php

index 42b2541..7d983fc 100644 (file)
@@ -13,13 +13,14 @@ namespace TYPO3\CMS\Form\Filter;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 
 /**
  * Title filter
  *
  * @author Patrick Broens <patrick@patrickbroens.nl>
  */
-class TitleCaseFilter implements \TYPO3\CMS\Form\Filter\FilterInterface {
+class TitleCaseFilter implements FilterInterface {
 
        /**
         * Convert alphabetic characters to title case
@@ -28,7 +29,15 @@ class TitleCaseFilter implements \TYPO3\CMS\Form\Filter\FilterInterface {
         * @return string
         */
        public function filter($value) {
-               return ucwords(strtolower((string) $value));
+               $tsfe = $this->getTypoScriptFrontendController();
+               $lower = $tsfe->csConvObj->conv_case($tsfe->renderCharset, $value, 'toLower');
+               return ucwords($lower);
        }
 
+       /**
+        * @return TypoScriptFrontendController
+        */
+       protected function getTypoScriptFrontendController() {
+               return $GLOBALS['TSFE'];
+       }
 }
index f6d049e..2e57f1e 100644 (file)
@@ -13,6 +13,8 @@ namespace TYPO3\CMS\Form\Tests\Unit\Filter;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Core\Charset\CharsetConverter;
+use TYPO3\CMS\Form\Filter\TitleCaseFilter;
 
 /**
  * Test case
@@ -22,7 +24,7 @@ namespace TYPO3\CMS\Form\Tests\Unit\Filter;
 class TitleCaseFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
-        * @var \TYPO3\CMS\Form\Filter\TitleCaseFilter
+        * @var TitleCaseFilter
         */
        protected $fixture = NULL;
 
@@ -30,9 +32,15 @@ class TitleCaseFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * Set up
         */
        public function setUp() {
-               $this->fixture = new \TYPO3\CMS\Form\Filter\TitleCaseFilter();
+               $this->fixture = new TitleCaseFilter();
+               $GLOBALS['TSFE'] = new \stdClass();
+               $GLOBALS['TSFE']->csConvObj = new CharsetConverter();
+               $GLOBALS['TSFE']->renderCharset = 'utf-8';
        }
 
+       /**
+        * @return array
+        */
        public function stringProvider() {
                return array(
                        'some text' => array('some text', 'Some Text'),