Fix incorrect handling of irregular values.

When inflecting irregular values, both plural and singular forms were
generated incorrectly.

Fixes #6538
This commit is contained in:
mark_story 2015-05-11 21:31:11 -04:00
parent efe82ea148
commit d4740c9c09
2 changed files with 5 additions and 2 deletions

View file

@ -123,6 +123,7 @@ class InflectorTest extends CakeTestCase {
$this->assertEquals(Inflector::singularize('fungi'), 'fungus');
$this->assertEquals(Inflector::singularize('nuclei'), 'nucleus');
$this->assertEquals(Inflector::singularize('octopuses'), 'octopus');
$this->assertEquals(Inflector::singularize('octopuses'), 'octopus');
$this->assertEquals(Inflector::singularize('radii'), 'radius');
$this->assertEquals(Inflector::singularize('stimuli'), 'stimulus');
$this->assertEquals(Inflector::singularize('syllabi'), 'syllabus');
@ -178,6 +179,7 @@ class InflectorTest extends CakeTestCase {
$this->assertEquals(Inflector::singularize('metadata'), 'metadata');
$this->assertEquals(Inflector::singularize('files_metadata'), 'files_metadata');
$this->assertEquals(Inflector::singularize('sieves'), 'sieve');
$this->assertEquals(Inflector::singularize('blue_octopuses'), 'blue_octopus');
$this->assertEquals(Inflector::singularize(''), '');
}
@ -250,6 +252,7 @@ class InflectorTest extends CakeTestCase {
$this->assertEquals(Inflector::pluralize('files_metadata'), 'files_metadata');
$this->assertEquals(Inflector::pluralize('stadia'), 'stadia');
$this->assertEquals(Inflector::pluralize('sieve'), 'sieves');
$this->assertEquals(Inflector::pluralize('blue_octopus'), 'blue_octopuses');
$this->assertEquals(Inflector::pluralize(''), '');
}

View file

@ -387,7 +387,7 @@ class Inflector {
}
if (preg_match('/(.*)\\b(' . self::$_plural['cacheIrregular'] . ')$/i', $word, $regs)) {
self::$_cache['pluralize'][$word] = $regs[1] . substr($word, 0, 1) . substr(self::$_plural['merged']['irregular'][strtolower($regs[2])], 1);
self::$_cache['pluralize'][$word] = $regs[1] . substr($regs[2], 0, 1) . substr(self::$_plural['merged']['irregular'][strtolower($regs[2])], 1);
return self::$_cache['pluralize'][$word];
}
@ -436,7 +436,7 @@ class Inflector {
}
if (preg_match('/(.*)\\b(' . self::$_singular['cacheIrregular'] . ')$/i', $word, $regs)) {
self::$_cache['singularize'][$word] = $regs[1] . substr($word, 0, 1) . substr(self::$_singular['merged']['irregular'][strtolower($regs[2])], 1);
self::$_cache['singularize'][$word] = $regs[1] . substr($regs[2], 0, 1) . substr(self::$_singular['merged']['irregular'][strtolower($regs[2])], 1);
return self::$_cache['singularize'][$word];
}