[BUGFIX] Use mbstring for capitalizing a string 22/49722/5
authorPhilipp Gampe <philipp.gampe@typo3.org>
Thu, 1 Sep 2016 15:07:17 +0000 (17:07 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Fri, 2 Sep 2016 19:21:38 +0000 (21:21 +0200)
If mbstring is available, use mb_convert_case instead of ucwords.

Resolves: #52244
Releases: master, 7.6
Change-Id: Ia6840fdda96d5511444afa014ebbcb01cbbf3ed0
Reviewed-on: https://review.typo3.org/49722
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org>
Tested-by: Philipp Gampe <philipp.gampe@typo3.org>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Marco Huber <mail@marco-huber.de>
Tested-by: Marco Huber <mail@marco-huber.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Charset/CharsetConverter.php
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php

index 7e90a2f..e52d62d 100644 (file)
@@ -1389,6 +1389,22 @@ class CharsetConverter implements SingletonInterface
     }
 
     /**
+     * Capitalize the given string
+     *
+     * @param string $charset
+     * @param string $string
+     * @return string
+     */
+    public function convCapitalize($charset, $string)
+    {
+        if ($this->getConversionStrategy() === self::STRATEGY_MBSTRING) {
+            return mb_convert_case($string, MB_CASE_TITLE, $charset);
+        } else {
+            return ucwords($string);
+        }
+    }
+
+    /**
      * Converts special chars (like æøåÆØÅ, umlauts etc) to ascii equivalents (usually double-bytes, like æ => ae etc.)
      *
      * @param string $charset Character set of string
index b7acfde..640962d 100644 (file)
@@ -6757,7 +6757,6 @@ class ContentObjectRenderer
      */
     public function caseshift($theValue, $case)
     {
-        /** @var CharsetConverter $charsetConverter */
         $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
         switch (strtolower($case)) {
             case 'upper':
@@ -6767,7 +6766,7 @@ class ContentObjectRenderer
                 $theValue = $charsetConverter->conv_case('utf-8', $theValue, 'toLower');
                 break;
             case 'capitalize':
-                $theValue = ucwords($theValue);
+                $theValue = $charsetConverter->convCapitalize('utf-8', $theValue);
                 break;
             case 'ucfirst':
                 $theValue = $charsetConverter->convCaseFirst('utf-8', $theValue, 'toUpper');