@@ -135,15 +135,21 @@ public function ascii(array $rules = []): self
135
135
} elseif (!\function_exists ('iconv ' )) {
136
136
$ s = preg_replace ('/[^\x00-\x7F]/u ' , '? ' , $ s );
137
137
} else {
138
- $ s = @preg_replace_callback ('/[^\x00-\x7F]/u ' , static function ($ c ) {
139
- $ c = (string ) iconv ('UTF-8 ' , 'ASCII//TRANSLIT ' , $ c [0 ]);
140
-
141
- if ('' === $ c && '' === iconv ('UTF-8 ' , 'ASCII//TRANSLIT ' , '² ' )) {
142
- throw new \LogicException (sprintf ('"%s" requires a translit-able iconv implementation, try installing "gnu-libiconv" if you \'re using Alpine Linux. ' , static ::class));
143
- }
138
+ $ previousLocale = setlocale (\LC_CTYPE , 0 );
139
+ try {
140
+ setlocale (\LC_CTYPE , 'C ' );
141
+ $ s = @preg_replace_callback ('/[^\x00-\x7F]/u ' , static function ($ c ) {
142
+ $ c = (string ) iconv ('UTF-8 ' , 'ASCII//TRANSLIT ' , $ c [0 ]);
143
+
144
+ if ('' === $ c && '' === iconv ('UTF-8 ' , 'ASCII//TRANSLIT ' , '² ' )) {
145
+ throw new \LogicException (sprintf ('"%s" requires a translit-able iconv implementation, try installing "gnu-libiconv" if you \'re using Alpine Linux. ' , static ::class));
146
+ }
144
147
145
- return 1 < \strlen ($ c ) ? ltrim ($ c , '\'`"^~ ' ) : ('' !== $ c ? $ c : '? ' );
146
- }, $ s );
148
+ return 1 < \strlen ($ c ) ? ltrim ($ c , '\'`"^~ ' ) : ('' !== $ c ? $ c : '? ' );
149
+ }, $ s );
150
+ } finally {
151
+ setlocale (\LC_CTYPE , $ previousLocale );
152
+ }
147
153
}
148
154
}
149
155
0 commit comments