diff --git a/docs/changelogs/v4.7.7.md b/docs/changelogs/v4.7.7.md index 391c732c6639..e4d6d900c090 100644 --- a/docs/changelogs/v4.7.7.md +++ b/docs/changelogs/v4.7.7.md @@ -31,6 +31,7 @@ Release Date: Unreleased - **Database:** Fixed a bug where `SQLite3\Connection::_foreignKeyData()` did not escape table identifiers in `PRAGMA foreign_key_list`, causing syntax errors on table names containing hyphens or schemas. - **Database:** Fixed a bug where `SQLite3\Table::dropIndexes()` used single-quoted string literals instead of escaped identifiers in `DROP INDEX IF EXISTS`, causing syntax errors on index names containing quotes or special characters. - **Helpers:** Fixed a bug where `excerpt()` threw a `TypeError` when `$phrase` was not found in `$text` or when `$phrase` was `null` and `$radius` was an odd integer. When `$phrase` is not found, `excerpt()` now falls back to extracting an excerpt from the beginning of `$text`. +- **Helpers:** Fixed a bug in `plural()` where the regex for `matrix`, `vertex`, and `index` lacked non-capturing grouping and an end-of-string anchor for the `ix` alternative, causing incorrect pluralization of words like `complex`, `sex`, and strings containing `matrix` before the end. Expanded `plural()` and `singular()` to support additional words ending in `ix` or `ex` (`apex`, `appendix`, `codex`, `cortex`, `latex`, `murex`, `vortex`). - **Helpers:** Fixed bugs in `ArrayHelper::dotKeyExists()` where `'0'` path segments caused early loop termination, non-array intermediate values threw a `TypeError`, and paths with segments after a wildcard failed when the wildcard matched multiple elements. - **Helpers:** Fixed escaping of attribute values in HTML media helpers to prevent malformed HTML and attribute injection. - **HTTP:** Fixed a bug where query-string based routing truncated additional query parameters in `SiteURIFactory::parseRequestURI()` due to incorrect array index access. diff --git a/system/Helpers/inflector_helper.php b/system/Helpers/inflector_helper.php index fb4ef6cb3924..c63b49252adc 100644 --- a/system/Helpers/inflector_helper.php +++ b/system/Helpers/inflector_helper.php @@ -31,8 +31,8 @@ function singular(string $string): string // Arranged in order. $singularRules = [ - '/(matr)ices$/' => '\1ix', - '/(vert|ind)ices$/' => '\1ex', + '/(matr|append)ices$/' => '\1ix', + '/(vert|ind|vort|cort|cod|lat|mur|ap)ices$/' => '\1ex', '/^(ox)en/' => '\1', '/(alias)es$/' => '\1', '/([octop|vir])i$/' => '\1us', @@ -89,26 +89,26 @@ function plural(string $string): string } $pluralRules = [ - '/(quiz)$/' => '\1zes', // quizzes - '/^(ox)$/' => '\1\2en', // ox - '/([m|l])ouse$/' => '\1ice', // mouse, louse - '/(matr|vert|ind)ix|ex$/' => '\1ices', // matrix, vertex, index - '/(x|ch|ss|sh)$/' => '\1es', // search, switch, fix, box, process, address - '/([^aeiouy]|qu)y$/' => '\1ies', // query, ability, agency - '/(hive)$/' => '\1s', // archive, hive - '/(?:([^f])fe|([lr])f)$/' => '\1\2ves', // half, safe, wife - '/sis$/' => 'ses', // basis, diagnosis - '/([ti])um$/' => '\1a', // datum, medium - '/(p)erson$/' => '\1eople', // person, salesperson - '/(m)an$/' => '\1en', // man, woman, spokesman - '/(c)hild$/' => '\1hildren', // child - '/(buffal|tomat)o$/' => '\1\2oes', // buffalo, tomato - '/(bu|campu)s$/' => '\1\2ses', // bus, campus - '/(alias|status|virus)$/' => '\1es', // alias - '/(octop)us$/' => '\1i', // octopus - '/(ax|cris|test)is$/' => '\1es', // axis, crisis - '/s$/' => 's', // no change (compatibility) - '/$/' => 's', + '/(quiz)$/' => '\1zes', // quizzes + '/^(ox)$/' => '\1\2en', // ox + '/([m|l])ouse$/' => '\1ice', // mouse, louse + '/(matr|vert|ind|vort|append|cort|cod|lat|mur|ap)(?:ix|ex)$/' => '\1ices', // matrix, vertex, index, vortex, appendix, cortex, codex, latex, murex, apex + '/(x|ch|ss|sh)$/' => '\1es', // search, switch, fix, box, process, address + '/([^aeiouy]|qu)y$/' => '\1ies', // query, ability, agency + '/(hive)$/' => '\1s', // archive, hive + '/(?:([^f])fe|([lr])f)$/' => '\1\2ves', // half, safe, wife + '/sis$/' => 'ses', // basis, diagnosis + '/([ti])um$/' => '\1a', // datum, medium + '/(p)erson$/' => '\1eople', // person, salesperson + '/(m)an$/' => '\1en', // man, woman, spokesman + '/(c)hild$/' => '\1hildren', // child + '/(buffal|tomat)o$/' => '\1\2oes', // buffalo, tomato + '/(bu|campu)s$/' => '\1\2ses', // bus, campus + '/(alias|status|virus)$/' => '\1es', // alias + '/(octop)us$/' => '\1i', // octopus + '/(ax|cris|test)is$/' => '\1es', // axis, crisis + '/s$/' => 's', // no change (compatibility) + '/$/' => 's', ]; foreach ($pluralRules as $rule => $replacement) { diff --git a/tests/system/Helpers/InflectorHelperTest.php b/tests/system/Helpers/InflectorHelperTest.php index 3d3079ec0880..0b974be8e2ff 100644 --- a/tests/system/Helpers/InflectorHelperTest.php +++ b/tests/system/Helpers/InflectorHelperTest.php @@ -33,32 +33,45 @@ protected function setUp(): void public function testSingular(): void { $strings = [ - 'matrices' => 'matrix', - 'oxen' => 'ox', - 'aliases' => 'alias', - 'octupus' => 'octupus', - 'shoes' => 'shoe', - 'buses' => 'bus', - 'campus' => 'campus', - 'campuses' => 'campus', - 'mice' => 'mouse', - 'movies' => 'movie', - 'series' => 'series', - 'hives' => 'hive', - 'lives' => 'life', - 'analyses' => 'analysis', - 'men' => 'man', - 'people' => 'person', - 'children' => 'child', - 'statuses' => 'status', - 'news' => 'news', - 'us' => 'us', - 'tests' => 'test', - 'queries' => 'query', - 'dogs' => 'dog', - 'cats' => 'cat', - 'families' => 'family', - 'countries' => 'country', + 'matrices' => 'matrix', + 'vertices' => 'vertex', + 'indices' => 'index', + 'apices' => 'apex', + 'appendices' => 'appendix', + 'codices' => 'codex', + 'cortices' => 'cortex', + 'latices' => 'latex', + 'murices' => 'murex', + 'vortices' => 'vortex', + 'complexes' => 'complex', + 'sexes' => 'sex', + 'annexes' => 'annex', + 'duplexes' => 'duplex', + 'oxen' => 'ox', + 'aliases' => 'alias', + 'octupus' => 'octupus', + 'shoes' => 'shoe', + 'buses' => 'bus', + 'campus' => 'campus', + 'campuses' => 'campus', + 'mice' => 'mouse', + 'movies' => 'movie', + 'series' => 'series', + 'hives' => 'hive', + 'lives' => 'life', + 'analyses' => 'analysis', + 'men' => 'man', + 'people' => 'person', + 'children' => 'child', + 'statuses' => 'status', + 'news' => 'news', + 'us' => 'us', + 'tests' => 'test', + 'queries' => 'query', + 'dogs' => 'dog', + 'cats' => 'cat', + 'families' => 'family', + 'countries' => 'country', ]; foreach ($strings as $pluralizedString => $singularizedString) { @@ -70,31 +83,45 @@ public function testSingular(): void public function testPlural(): void { $strings = [ - 'searches' => 'search', - 'matrices' => 'matrix', - 'oxen' => 'ox', - 'aliases' => 'alias', - 'octupus' => 'octupus', - 'shoes' => 'shoe', - 'buses' => 'bus', - 'mice' => 'mouse', - 'movies' => 'movie', - 'series' => 'series', - 'hives' => 'hive', - 'lives' => 'life', - 'analyses' => 'analysis', - 'men' => 'man', - 'people' => 'person', - 'children' => 'child', - 'statuses' => 'status', - 'news' => 'news', - 'us' => 'us', - 'tests' => 'test', - 'queries' => 'query', - 'dogs' => 'dog', - 'cats' => 'cat', - 'families' => 'family', - 'countries' => 'country', + 'searches' => 'search', + 'matrices' => 'matrix', + 'vertices' => 'vertex', + 'indices' => 'index', + 'apices' => 'apex', + 'appendices' => 'appendix', + 'codices' => 'codex', + 'cortices' => 'cortex', + 'latices' => 'latex', + 'murices' => 'murex', + 'vortices' => 'vortex', + 'complexes' => 'complex', + 'sexes' => 'sex', + 'annexes' => 'annex', + 'duplexes' => 'duplex', + 'matrix_ids' => 'matrix_id', + 'oxen' => 'ox', + 'aliases' => 'alias', + 'octupus' => 'octupus', + 'shoes' => 'shoe', + 'buses' => 'bus', + 'mice' => 'mouse', + 'movies' => 'movie', + 'series' => 'series', + 'hives' => 'hive', + 'lives' => 'life', + 'analyses' => 'analysis', + 'men' => 'man', + 'people' => 'person', + 'children' => 'child', + 'statuses' => 'status', + 'news' => 'news', + 'us' => 'us', + 'tests' => 'test', + 'queries' => 'query', + 'dogs' => 'dog', + 'cats' => 'cat', + 'families' => 'family', + 'countries' => 'country', ]; foreach ($strings as $pluralizedString => $singularizedString) {