Skip to content

Commit e9620ad

Browse files
committed
[Inflector][String] Fix Notice when argument is empty string
1 parent 586f5b7 commit e9620ad

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/Symfony/Component/String/Inflector/EnglishInflector.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ public function singularize(string $plural): array
325325
$lowerPluralRev = strtolower($pluralRev);
326326
$pluralLength = \strlen($lowerPluralRev);
327327

328-
// Check if the word is one which is not inflected, return early if so
329-
if (\in_array($lowerPluralRev, self::$uninflected, true)) {
328+
// Check if the word is one which is not inflected or is an empty string, return early if so
329+
if (\in_array($lowerPluralRev, self::$uninflected, true) || 0 === $pluralLength) {
330330
return [$plural];
331331
}
332332

@@ -404,8 +404,8 @@ public function pluralize(string $singular): array
404404
$lowerSingularRev = strtolower($singularRev);
405405
$singularLength = \strlen($lowerSingularRev);
406406

407-
// Check if the word is one which is not inflected, return early if so
408-
if (\in_array($lowerSingularRev, self::$uninflected, true)) {
407+
// Check if the word is one which is not inflected or is an empty string, return early if so
408+
if (\in_array($lowerSingularRev, self::$uninflected, true) || 0 === $singularLength) {
409409
return [$singular];
410410
}
411411

src/Symfony/Component/String/Tests/EnglishInflectorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,16 @@ public function testPluralize(string $singular, $plural)
306306
{
307307
$this->assertSame(\is_array($plural) ? $plural : [$plural], (new EnglishInflector())->pluralize($singular));
308308
}
309+
310+
public function testPluralizeEmptyString()
311+
{
312+
$plural = (new EnglishInflector())->pluralize('');
313+
$this->assertSame([''], $plural);
314+
}
315+
316+
public function testSingularizeEmptyString()
317+
{
318+
$singular = (new EnglishInflector())->singularize('');
319+
$this->assertSame([''], $singular);
320+
}
309321
}

0 commit comments

Comments
 (0)