mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix issue with overlapping irregular inflections.
When irregular inflections overlap we should choose the longest match, not the shortest. Refs #6659
This commit is contained in:
parent
523597df43
commit
df0f2295c3
2 changed files with 54 additions and 4 deletions
|
@ -183,6 +183,29 @@ class InflectorTest extends CakeTestCase {
|
|||
$this->assertEquals(Inflector::singularize(''), '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that overlapping irregulars don't collide.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSingularizeMultiWordIrregular() {
|
||||
Inflector::rules('singular', array(
|
||||
'irregular' => array(
|
||||
'preguntas_frecuentes' => 'pregunta_frecuente',
|
||||
'categorias_preguntas_frecuentes' => 'categoria_pregunta_frecuente',
|
||||
)
|
||||
));
|
||||
$this->assertEquals('pregunta_frecuente', Inflector::singularize('preguntas_frecuentes'));
|
||||
$this->assertEquals(
|
||||
'categoria_pregunta_frecuente',
|
||||
Inflector::singularize('categorias_preguntas_frecuentes')
|
||||
);
|
||||
$this->assertEquals(
|
||||
'faq_categoria_pregunta_frecuente',
|
||||
Inflector::singularize('faq_categorias_preguntas_frecuentes')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* testInflectingPlurals method
|
||||
*
|
||||
|
@ -256,6 +279,29 @@ class InflectorTest extends CakeTestCase {
|
|||
$this->assertEquals(Inflector::pluralize(''), '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that overlapping irregulars don't collide.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPluralizeMultiWordIrregular() {
|
||||
Inflector::rules('plural', array(
|
||||
'irregular' => array(
|
||||
'pregunta_frecuente' => 'preguntas_frecuentes',
|
||||
'categoria_pregunta_frecuente' => 'categorias_preguntas_frecuentes',
|
||||
)
|
||||
));
|
||||
$this->assertEquals('preguntas_frecuentes', Inflector::pluralize('pregunta_frecuente'));
|
||||
$this->assertEquals(
|
||||
'categorias_preguntas_frecuentes',
|
||||
Inflector::pluralize('categoria_pregunta_frecuente')
|
||||
);
|
||||
$this->assertEquals(
|
||||
'faq_categorias_preguntas_frecuentes',
|
||||
Inflector::pluralize('faq_categoria_pregunta_frecuente')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* testInflectingMultiWordIrregulars
|
||||
*
|
||||
|
|
|
@ -386,8 +386,10 @@ class Inflector {
|
|||
self::$_plural['cacheIrregular'] = '(?:' . implode('|', array_keys(self::$_plural['merged']['irregular'])) . ')';
|
||||
}
|
||||
|
||||
if (preg_match('/(.*(?:\\b|_))(' . self::$_plural['cacheIrregular'] . ')$/i', $word, $regs)) {
|
||||
self::$_cache['pluralize'][$word] = $regs[1] . substr($regs[2], 0, 1) . substr(self::$_plural['merged']['irregular'][strtolower($regs[2])], 1);
|
||||
if (preg_match('/(.*?(?:\\b|_))(' . self::$_plural['cacheIrregular'] . ')$/i', $word, $regs)) {
|
||||
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];
|
||||
}
|
||||
|
||||
|
@ -435,8 +437,10 @@ class Inflector {
|
|||
self::$_singular['cacheIrregular'] = '(?:' . implode('|', array_keys(self::$_singular['merged']['irregular'])) . ')';
|
||||
}
|
||||
|
||||
if (preg_match('/(.*(?:\\b|_))(' . self::$_singular['cacheIrregular'] . ')$/i', $word, $regs)) {
|
||||
self::$_cache['singularize'][$word] = $regs[1] . substr($regs[2], 0, 1) . substr(self::$_singular['merged']['irregular'][strtolower($regs[2])], 1);
|
||||
if (preg_match('/(.*?(?:\\b|_))(' . self::$_singular['cacheIrregular'] . ')$/i', $word, $regs)) {
|
||||
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];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue