From fd18148354687c471d5098c584a27e54a471a9a5 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Sun, 29 May 2016 18:16:27 +0200 Subject: [PATCH 1/4] Fixed singular of committee --- src/Symfony/Component/PropertyAccess/StringUtil.php | 8 ++++++-- .../Component/PropertyAccess/Tests/StringUtilTest.php | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/PropertyAccess/StringUtil.php b/src/Symfony/Component/PropertyAccess/StringUtil.php index 248a6483d8b0a..ee2a27a069c4a 100644 --- a/src/Symfony/Component/PropertyAccess/StringUtil.php +++ b/src/Symfony/Component/PropertyAccess/StringUtil.php @@ -24,7 +24,6 @@ class StringUtil * @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 @@ -211,8 +210,13 @@ public static function singularify($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/PropertyAccess/Tests/StringUtilTest.php b/src/Symfony/Component/PropertyAccess/Tests/StringUtilTest.php index 0fd6bb69b2956..516f151b23ecc 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/StringUtilTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/StringUtilTest.php @@ -53,6 +53,7 @@ public function singularifyProvider() 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 27eda6925f50eda57055ecf69626d3e3889d43e6 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Sun, 5 Jun 2016 10:42:31 +0200 Subject: [PATCH 2/4] Refactored array to private static variable --- .../Component/PropertyAccess/StringUtil.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/PropertyAccess/StringUtil.php b/src/Symfony/Component/PropertyAccess/StringUtil.php index ee2a27a069c4a..2031f9eebca0a 100644 --- a/src/Symfony/Component/PropertyAccess/StringUtil.php +++ b/src/Symfony/Component/PropertyAccess/StringUtil.php @@ -125,6 +125,16 @@ class StringUtil array('xuae', 4, false, true, 'eau'), ); + /** + * 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. */ @@ -210,13 +220,8 @@ public static function singularify($plural) } } - $irregularNouns = array( - 'committee' => 'committee', - 'feedback' => 'feedback', - ); - // 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 4ed1ed15242d6c7687931e51b64eb27588a25d04 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Sun, 5 Jun 2016 19:50:19 +0200 Subject: [PATCH 3/4] Added screenshots --- src/Symfony/Component/PropertyAccess/StringUtil.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Component/PropertyAccess/StringUtil.php b/src/Symfony/Component/PropertyAccess/StringUtil.php index 2031f9eebca0a..4d22f41349ca5 100644 --- a/src/Symfony/Component/PropertyAccess/StringUtil.php +++ b/src/Symfony/Component/PropertyAccess/StringUtil.php @@ -133,6 +133,7 @@ class StringUtil private static $irregularNouns = array( 'committee' => 'committee', 'feedback' => 'feedback', + 'screenshots' => 'screenshot', ); /** From e21c52fa18cb684c3c38866f7b334cad3a31546e Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Mon, 6 Jun 2016 20:51:33 +0200 Subject: [PATCH 4/4] Switched the conversion ee to oo to a whitelist approach --- .../Component/PropertyAccess/StringUtil.php | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Component/PropertyAccess/StringUtil.php b/src/Symfony/Component/PropertyAccess/StringUtil.php index 4d22f41349ca5..5cbd3622f9a5d 100644 --- a/src/Symfony/Component/PropertyAccess/StringUtil.php +++ b/src/Symfony/Component/PropertyAccess/StringUtil.php @@ -68,6 +68,15 @@ class StringUtil // 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'), @@ -125,17 +134,6 @@ class StringUtil array('xuae', 4, false, true, 'eau'), ); - /** - * 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. */ @@ -221,11 +219,6 @@ public static function singularify($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; }