Skip to content

Commit f3570b8

Browse files
committed
Merge branch '7.2' into 7.3
* 7.2: Support nexus -> nexuses pluralization [Lock] read (possible) error from Redis instance where evalSha() was called ignore the current locale before transliterating ASCII codes with iconv()
2 parents a751100 + a214fe7 commit f3570b8

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

AbstractUnicodeString.php

+14-8
Original file line numberDiff line numberDiff line change
@@ -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

Inflector/EnglishInflector.php

+3
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ final class EnglishInflector implements InflectorInterface
333333
// conspectuses (conspectus), prospectuses (prospectus)
334334
['sutcep', 6, true, true, 'pectuses'],
335335

336+
// nexuses (nexus)
337+
['suxen', 5, false, false, 'nexuses'],
338+
336339
// fungi (fungus), alumni (alumnus), syllabi (syllabus), radii (radius)
337340
['su', 2, true, true, 'i'],
338341

Tests/Slugger/AsciiSluggerTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,19 @@ public static function provideSlugEmojiTests(): iterable
106106
'undefined_locale', // Behaves the same as if emoji support is disabled
107107
];
108108
}
109+
110+
/**
111+
* @requires extension intl
112+
*/
113+
public function testSlugEmojiWithSetLocale()
114+
{
115+
if (!setlocale(LC_ALL, 'C.UTF-8')) {
116+
$this->markTestSkipped('Unable to switch to the "C.UTF-8" locale.');
117+
}
118+
119+
$slugger = new AsciiSlugger();
120+
$slugger = $slugger->withEmoji(true);
121+
122+
$this->assertSame('a-and-a-go-to', (string) $slugger->slug('a 😺, 🐈‍⬛, and a 🦁 go to 🏞️... 😍 🎉 💛', '-'));
123+
}
109124
}

0 commit comments

Comments
 (0)