From 8f2a2af51d60c5e1fe2a39ad63307de09b7145b2 Mon Sep 17 00:00:00 2001 From: Sergey Podgornyy Date: Wed, 28 Feb 2018 09:08:26 +0100 Subject: [PATCH 1/2] Str: Refactor languageSpecificCharsArray() --- src/Illuminate/Support/Str.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index eb1d94e7d0de..45de1f58fc3d 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -56,8 +56,8 @@ public static function ascii($value, $language = 'en') { $languageSpecific = static::languageSpecificCharsArray($language); - if (! is_null($languageSpecific)) { - $value = str_replace($languageSpecific[0], $languageSpecific[1], $value); + if ($languageSpecific !== null) { + $value = str_replace(array_keys($languageSpecific), array_values($languageSpecific), $value); } foreach (static::charsArray() as $key => $val) { @@ -703,12 +703,22 @@ protected static function languageSpecificCharsArray($language) if (! isset($languageSpecific)) { $languageSpecific = [ 'bg' => [ - ['х', 'Х', 'щ', 'Щ', 'ъ', 'Ъ', 'ь', 'Ь'], - ['h', 'H', 'sht', 'SHT', 'a', 'А', 'y', 'Y'], + 'х' => 'h', + 'Х' => 'H', + 'щ' => 'sht', + 'Щ' => 'SHT', + 'ъ' => 'a', + 'Ъ' => 'А', + 'ь' => 'y', + 'Ь' => 'Y', ], 'de' => [ - ['ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü'], - ['ae', 'oe', 'ue', 'AE', 'OE', 'UE'], + 'ä' => 'ae', + 'ö' => 'oe', + 'ü' => 'ue', + 'Ä' => 'AE', + 'Ö' => 'OE', + 'Ü' => 'UE', ], ]; } From 4ca0c1d43f7e020baf62bb0c0b709e151f094f4c Mon Sep 17 00:00:00 2001 From: Sergey Podgornyy Date: Wed, 28 Feb 2018 10:43:44 +0100 Subject: [PATCH 2/2] Roll back is_null improvement in Str::ascii() --- src/Illuminate/Support/Str.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 45de1f58fc3d..ab7307ac41e5 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -56,7 +56,7 @@ public static function ascii($value, $language = 'en') { $languageSpecific = static::languageSpecificCharsArray($language); - if ($languageSpecific !== null) { + if (! is_null($languageSpecific)) { $value = str_replace(array_keys($languageSpecific), array_values($languageSpecific), $value); }