@@ -135,15 +135,21 @@ public function ascii(array $rules = []): self
135135 } elseif (!\function_exists ('iconv ' )) {
136136 $ s = preg_replace ('/[^\x00-\x7F]/u ' , '? ' , $ s );
137137 } 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+ }
144147
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+ }
147153 }
148154 }
149155
0 commit comments