From 3bd0571e6b1ea2173cb14410a374a9c7d6e3896e Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Sun, 29 May 2016 14:11:17 +0200 Subject: [PATCH 1/4] Fixed singular of committee --- src/Symfony/Component/Inflector/Inflector.php | 8 ++++++-- src/Symfony/Component/Inflector/Tests/InflectorTest.php | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Inflector/Inflector.php b/src/Symfony/Component/Inflector/Inflector.php index 7b227c5ac60a8..4ee55d42da8e2 100644 --- a/src/Symfony/Component/Inflector/Inflector.php +++ b/src/Symfony/Component/Inflector/Inflector.php @@ -26,7 +26,6 @@ final class Inflector * @var array * * @see http://english-zone.com/spelling/plurals.html - * @see http://www.scribd.com/doc/3271143/List-of-100-Irregular-Plural-Nouns-in-English */ private static $pluralMap = array( // First entry: plural suffix, reversed @@ -218,8 +217,13 @@ public static function singularize($plural) } } + $irregularNouns = array( + 'committee' => 'committee', + 'feedback' => 'feedback', + ); + // Convert teeth to tooth, feet to foot - if (false !== ($pos = strpos($plural, 'ee')) && strlen($plural) > 3 && 'feedback' !== $plural) { + if (false !== ($pos = strpos($plural, 'ee')) && strlen($plural) > 3 && !isset($irregularNouns[strtolower($plural)])) { return substr_replace($plural, 'oo', $pos, 2); } diff --git a/src/Symfony/Component/Inflector/Tests/InflectorTest.php b/src/Symfony/Component/Inflector/Tests/InflectorTest.php index 43aa682f37565..0c0d702dd8b47 100644 --- a/src/Symfony/Component/Inflector/Tests/InflectorTest.php +++ b/src/Symfony/Component/Inflector/Tests/InflectorTest.php @@ -53,6 +53,7 @@ public function singularizeProvider() array('children', 'child'), array('circuses', array('circus', 'circuse', 'circusis')), array('cliffs', 'cliff'), + array('committee', 'committee'), array('crises', array('cris', 'crise', 'crisis')), array('criteria', array('criterion', 'criterium')), array('cups', 'cup'), From 9c99398f0e6136b63b0fde74b48110c67dd2ba31 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Sun, 5 Jun 2016 10:43:59 +0200 Subject: [PATCH 2/4] Refactored array to private static variable --- src/Symfony/Component/Inflector/Inflector.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Inflector/Inflector.php b/src/Symfony/Component/Inflector/Inflector.php index 4ee55d42da8e2..daa03774c9d25 100644 --- a/src/Symfony/Component/Inflector/Inflector.php +++ b/src/Symfony/Component/Inflector/Inflector.php @@ -130,6 +130,16 @@ final class Inflector array('elpoep', 6, true, true, 'person'), ); + /** + * Irregular nouns which will not be converted 'ee' to 'oo' + * + * @var array + */ + private static $irregularNouns = array( + 'committee' => 'committee', + 'feedback' => 'feedback', + ); + /** * This class should not be instantiated. */ @@ -223,7 +233,7 @@ public static function singularize($plural) ); // Convert teeth to tooth, feet to foot - if (false !== ($pos = strpos($plural, 'ee')) && strlen($plural) > 3 && !isset($irregularNouns[strtolower($plural)])) { + if (false !== ($pos = strpos($plural, 'ee')) && strlen($plural) > 3 && !isset(self::$irregularNouns[strtolower($plural)])) { return substr_replace($plural, 'oo', $pos, 2); } From 2dcd773228713f3a9cf3163a466620a983982666 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Sun, 5 Jun 2016 19:52:18 +0200 Subject: [PATCH 3/4] Added singular of screenshots --- src/Symfony/Component/Inflector/Inflector.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Symfony/Component/Inflector/Inflector.php b/src/Symfony/Component/Inflector/Inflector.php index daa03774c9d25..010c20c1f253f 100644 --- a/src/Symfony/Component/Inflector/Inflector.php +++ b/src/Symfony/Component/Inflector/Inflector.php @@ -138,6 +138,7 @@ final class Inflector private static $irregularNouns = array( 'committee' => 'committee', 'feedback' => 'feedback', + 'screenshots' => 'screenshot', ); /** @@ -227,11 +228,6 @@ public static function singularize($plural) } } - $irregularNouns = array( - 'committee' => 'committee', - 'feedback' => 'feedback', - ); - // Convert teeth to tooth, feet to foot if (false !== ($pos = strpos($plural, 'ee')) && strlen($plural) > 3 && !isset(self::$irregularNouns[strtolower($plural)])) { return substr_replace($plural, 'oo', $pos, 2); From 91ab25a07ed2a2cdd2003b44ac499de9e5f63225 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Mon, 6 Jun 2016 20:47:09 +0200 Subject: [PATCH 4/4] Switched the conversion ee to oo to a whitelist approach --- src/Symfony/Component/Inflector/Inflector.php | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Component/Inflector/Inflector.php b/src/Symfony/Component/Inflector/Inflector.php index 010c20c1f253f..fbe8cc8a45c72 100644 --- a/src/Symfony/Component/Inflector/Inflector.php +++ b/src/Symfony/Component/Inflector/Inflector.php @@ -70,6 +70,15 @@ final class Inflector // movies (movie) array('seivom', 6, true, true, 'movie'), + // feet (foot) + array('teef', 4, true, true, 'foot'), + + // geese (goose) + array('eseeg', 5, true, true, 'goose'), + + // teeth (tooth) + array('hteet', 5, true, true, 'tooth'), + // news (news) array('swen', 4, true, true, 'news'), @@ -130,17 +139,6 @@ final class Inflector array('elpoep', 6, true, true, 'person'), ); - /** - * Irregular nouns which will not be converted 'ee' to 'oo' - * - * @var array - */ - private static $irregularNouns = array( - 'committee' => 'committee', - 'feedback' => 'feedback', - 'screenshots' => 'screenshot', - ); - /** * This class should not be instantiated. */ @@ -228,11 +226,6 @@ public static function singularize($plural) } } - // Convert teeth to tooth, feet to foot - if (false !== ($pos = strpos($plural, 'ee')) && strlen($plural) > 3 && !isset(self::$irregularNouns[strtolower($plural)])) { - return substr_replace($plural, 'oo', $pos, 2); - } - // Assume that plural and singular is identical return $plural; }