From 733ddc7ff447bbb6ed036363b951768ca402fccb Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 26 May 2015 22:51:00 -0400 Subject: [PATCH] Use mb* functions in Inflector humanize/underscore. Use the mbstring shims we already provide to make Inflector more robust than it currently is. This solves the invalid ID attribute generation in a way that never varies between environments. Refs #6635 --- lib/Cake/Utility/Inflector.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/Cake/Utility/Inflector.php b/lib/Cake/Utility/Inflector.php index 79eb448f3..61a63c2a1 100644 --- a/lib/Cake/Utility/Inflector.php +++ b/lib/Cake/Utility/Inflector.php @@ -480,11 +480,7 @@ class Inflector { public static function underscore($camelCasedWord) { if (!($result = self::_cache(__FUNCTION__, $camelCasedWord))) { $underscoredWord = preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord); - if (function_exists('mb_convert_case')) { - $result = mb_convert_case($underscoredWord, MB_CASE_LOWER, Configure::read('App.encoding')); - } else { - $result = strtolower($underscoredWord); - } + $result = mb_strtolower($underscoredWord); self::_cache(__FUNCTION__, $camelCasedWord, $result); } return $result; @@ -501,12 +497,11 @@ class Inflector { public static function humanize($lowerCaseAndUnderscoredWord) { if (!($result = self::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord))) { $lowerCaseAndUnderscoredWord = self::underscore($lowerCaseAndUnderscoredWord); - $result = str_replace('_', ' ', $lowerCaseAndUnderscoredWord); - if (function_exists('mb_convert_case')) { - $result = mb_convert_case($result, MB_CASE_TITLE, Configure::read('App.encoding')); - } else { - $result = ucwords($result); + $result = explode(' ', str_replace('_', ' ', $lowerCaseAndUnderscoredWord)); + foreach ($result as &$word) { + $word = mb_strtoupper(mb_substr($word, 0, 1)) . mb_substr($word, 1); } + $result = implode(' ', $result); self::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord, $result); } return $result;