diff --git a/src/system/Papaya/Util/String/Utf8.php b/src/system/Papaya/Util/String/Utf8.php index 193a554fd..d1249979f 100644 --- a/src/system/Papaya/Util/String/Utf8.php +++ b/src/system/Papaya/Util/String/Utf8.php @@ -225,7 +225,13 @@ public static function toLowerCase($string) { case self::EXT_MBSTRING : return mb_strtolower($string, 'utf-8'); } - return $string; + return preg_replace_callback( + '([A-Z]+)u', + function($match) { + return strtolower($match[0]); + }, + $string + ); } public static function toUpperCase($string) { @@ -240,7 +246,13 @@ public static function toUpperCase($string) { case self::EXT_MBSTRING : return mb_strtoupper($string, 'utf-8'); } - return $string; + return preg_replace_callback( + '([a-z]+)u', + function($match) { + return strtoupper($match[0]); + }, + $string + ); } /** @@ -274,4 +286,4 @@ public static function getExtension() { public static function setExtension($extension) { self::$extension = (int)$extension; } -} \ No newline at end of file +} diff --git a/tests/system/Papaya/Util/String/Utf8Test.php b/tests/system/Papaya/Util/String/Utf8Test.php index f8193d822..138f86cda 100644 --- a/tests/system/Papaya/Util/String/Utf8Test.php +++ b/tests/system/Papaya/Util/String/Utf8Test.php @@ -114,6 +114,32 @@ public function testCopyUsingPcreFallback($expected, $haystack, $start, $length } /** + * @param string $expected + * @param string $input + * @covers PapayaUtilStringUtf8::toLowerCase + * @testWith + * ["abc", "ABC"] + * ["abcÄdef", "ABCÄDEF"] + */ + public function testLowerCaseUsingPcreFallback($expected, $input) { + PapayaUtilStringUtf8::setExtension(PapayaUtilStringUtf8::EXT_PCRE); + $this->assertEquals($expected, PapayaUtilStringUtf8::toLowerCase($input)); + } + + /** + * @param string $expected + * @param string $input + * @covers PapayaUtilStringUtf8::toUpperCase + * @testWith + * ["ABC", "abc"] + * ["ABCäDEF", "abcädef"] + */ + public function testUpperCaseUsingPcreFallback($expected, $input) { + PapayaUtilStringUtf8::setExtension(PapayaUtilStringUtf8::EXT_PCRE); + $this->assertEquals($expected, PapayaUtilStringUtf8::toUpperCase($input)); + } + + /** * @covers PapayaUtilStringUtf8::getExtension */ public function testGetExtension() { @@ -205,4 +231,4 @@ public static function provideCopySamples() { 'ascii 10, 10' => array('', 'ascii', 10, 10) ); } -} \ No newline at end of file +}