Skip to content

Commit ed95f0e

Browse files
authored
fix(Helpers): fix matrix and vertex regex grouping in plural() (#10782)
1 parent ff76fcf commit ed95f0e

3 files changed

Lines changed: 102 additions & 73 deletions

File tree

‎docs/changelogs/v4.7.7.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Release Date: Unreleased
3737
- **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`.
3838
- **Helpers:** Fixed a bug where `format_number()` with `$precision = 0` appended a trailing comma in locales using a comma as the decimal separator.
3939
- **Helpers:** Fixed a bug where `parse_subdomain()` incorrectly treated hostnames with ports (such as IP addresses and two-part TLD domains) as having unexpected subdomains.
40+
- **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`).
4041
- **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.
4142
- **Helpers:** Fixed escaping of attribute values in HTML media helpers to prevent malformed HTML and attribute injection.
4243
- **HTTP:** Fixed a bug where query-string based routing truncated additional query parameters in `SiteURIFactory::parseRequestURI()` due to incorrect array index access.

‎system/Helpers/inflector_helper.php‎

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ function singular(string $string): string
3131

3232
// Arranged in order.
3333
$singularRules = [
34-
'/(matr)ices$/' => '\1ix',
35-
'/(vert|ind)ices$/' => '\1ex',
34+
'/(matr|append)ices$/' => '\1ix',
35+
'/(vert|ind|vort|cort|cod|lat|mur|ap)ices$/' => '\1ex',
3636
'/^(ox)en/' => '\1',
3737
'/(alias)es$/' => '\1',
3838
'/([octop|vir])i$/' => '\1us',
@@ -89,26 +89,27 @@ function plural(string $string): string
8989
}
9090

9191
$pluralRules = [
92-
'/(quiz)$/' => '\1zes', // quizzes
93-
'/^(ox)$/' => '\1\2en', // ox
94-
'/([m|l])ouse$/' => '\1ice', // mouse, louse
95-
'/(matr|vert|ind)ix|ex$/' => '\1ices', // matrix, vertex, index
96-
'/(x|ch|ss|sh)$/' => '\1es', // search, switch, fix, box, process, address
97-
'/([^aeiouy]|qu)y$/' => '\1ies', // query, ability, agency
98-
'/(hive)$/' => '\1s', // archive, hive
99-
'/(?:([^f])fe|([lr])f)$/' => '\1\2ves', // half, safe, wife
100-
'/sis$/' => 'ses', // basis, diagnosis
101-
'/([ti])um$/' => '\1a', // datum, medium
102-
'/(p)erson$/' => '\1eople', // person, salesperson
103-
'/(m)an$/' => '\1en', // man, woman, spokesman
104-
'/(c)hild$/' => '\1hildren', // child
105-
'/(buffal|tomat)o$/' => '\1\2oes', // buffalo, tomato
106-
'/(bu|campu)s$/' => '\1\2ses', // bus, campus
107-
'/(alias|status|virus)$/' => '\1es', // alias
108-
'/(octop)us$/' => '\1i', // octopus
109-
'/(ax|cris|test)is$/' => '\1es', // axis, crisis
110-
'/s$/' => 's', // no change (compatibility)
111-
'/$/' => 's',
92+
'/(quiz)$/' => '\1zes', // quizzes
93+
'/^(ox)$/' => '\1\2en', // ox
94+
'/([m|l])ouse$/' => '\1ice', // mouse, louse
95+
'/(matr|append)ix$/' => '\1ices', // matrix, appendix
96+
'/(vert|ind|vort|cort|cod|lat|mur|ap)ex$/' => '\1ices', // vertex, index, vortex, cortex, codex, latex, murex, apex
97+
'/(x|ch|ss|sh)$/' => '\1es', // search, switch, fix, box, process, address
98+
'/([^aeiouy]|qu)y$/' => '\1ies', // query, ability, agency
99+
'/(hive)$/' => '\1s', // archive, hive
100+
'/(?:([^f])fe|([lr])f)$/' => '\1\2ves', // half, safe, wife
101+
'/sis$/' => 'ses', // basis, diagnosis
102+
'/([ti])um$/' => '\1a', // datum, medium
103+
'/(p)erson$/' => '\1eople', // person, salesperson
104+
'/(m)an$/' => '\1en', // man, woman, spokesman
105+
'/(c)hild$/' => '\1hildren', // child
106+
'/(buffal|tomat)o$/' => '\1\2oes', // buffalo, tomato
107+
'/(bu|campu)s$/' => '\1\2ses', // bus, campus
108+
'/(alias|status|virus)$/' => '\1es', // alias
109+
'/(octop)us$/' => '\1i', // octopus
110+
'/(ax|cris|test)is$/' => '\1es', // axis, crisis
111+
'/s$/' => 's', // no change (compatibility)
112+
'/$/' => 's',
112113
];
113114

114115
foreach ($pluralRules as $rule => $replacement) {

‎tests/system/Helpers/InflectorHelperTest.php‎

Lines changed: 78 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,45 @@ protected function setUp(): void
3333
public function testSingular(): void
3434
{
3535
$strings = [
36-
'matrices' => 'matrix',
37-
'oxen' => 'ox',
38-
'aliases' => 'alias',
39-
'octupus' => 'octupus',
40-
'shoes' => 'shoe',
41-
'buses' => 'bus',
42-
'campus' => 'campus',
43-
'campuses' => 'campus',
44-
'mice' => 'mouse',
45-
'movies' => 'movie',
46-
'series' => 'series',
47-
'hives' => 'hive',
48-
'lives' => 'life',
49-
'analyses' => 'analysis',
50-
'men' => 'man',
51-
'people' => 'person',
52-
'children' => 'child',
53-
'statuses' => 'status',
54-
'news' => 'news',
55-
'us' => 'us',
56-
'tests' => 'test',
57-
'queries' => 'query',
58-
'dogs' => 'dog',
59-
'cats' => 'cat',
60-
'families' => 'family',
61-
'countries' => 'country',
36+
'matrices' => 'matrix',
37+
'vertices' => 'vertex',
38+
'indices' => 'index',
39+
'apices' => 'apex',
40+
'appendices' => 'appendix',
41+
'codices' => 'codex',
42+
'cortices' => 'cortex',
43+
'latices' => 'latex',
44+
'murices' => 'murex',
45+
'vortices' => 'vortex',
46+
'complexes' => 'complex',
47+
'sexes' => 'sex',
48+
'annexes' => 'annex',
49+
'duplexes' => 'duplex',
50+
'oxen' => 'ox',
51+
'aliases' => 'alias',
52+
'octupus' => 'octupus',
53+
'shoes' => 'shoe',
54+
'buses' => 'bus',
55+
'campus' => 'campus',
56+
'campuses' => 'campus',
57+
'mice' => 'mouse',
58+
'movies' => 'movie',
59+
'series' => 'series',
60+
'hives' => 'hive',
61+
'lives' => 'life',
62+
'analyses' => 'analysis',
63+
'men' => 'man',
64+
'people' => 'person',
65+
'children' => 'child',
66+
'statuses' => 'status',
67+
'news' => 'news',
68+
'us' => 'us',
69+
'tests' => 'test',
70+
'queries' => 'query',
71+
'dogs' => 'dog',
72+
'cats' => 'cat',
73+
'families' => 'family',
74+
'countries' => 'country',
6275
];
6376

6477
foreach ($strings as $pluralizedString => $singularizedString) {
@@ -70,31 +83,45 @@ public function testSingular(): void
7083
public function testPlural(): void
7184
{
7285
$strings = [
73-
'searches' => 'search',
74-
'matrices' => 'matrix',
75-
'oxen' => 'ox',
76-
'aliases' => 'alias',
77-
'octupus' => 'octupus',
78-
'shoes' => 'shoe',
79-
'buses' => 'bus',
80-
'mice' => 'mouse',
81-
'movies' => 'movie',
82-
'series' => 'series',
83-
'hives' => 'hive',
84-
'lives' => 'life',
85-
'analyses' => 'analysis',
86-
'men' => 'man',
87-
'people' => 'person',
88-
'children' => 'child',
89-
'statuses' => 'status',
90-
'news' => 'news',
91-
'us' => 'us',
92-
'tests' => 'test',
93-
'queries' => 'query',
94-
'dogs' => 'dog',
95-
'cats' => 'cat',
96-
'families' => 'family',
97-
'countries' => 'country',
86+
'searches' => 'search',
87+
'matrices' => 'matrix',
88+
'vertices' => 'vertex',
89+
'indices' => 'index',
90+
'apices' => 'apex',
91+
'appendices' => 'appendix',
92+
'codices' => 'codex',
93+
'cortices' => 'cortex',
94+
'latices' => 'latex',
95+
'murices' => 'murex',
96+
'vortices' => 'vortex',
97+
'complexes' => 'complex',
98+
'sexes' => 'sex',
99+
'annexes' => 'annex',
100+
'duplexes' => 'duplex',
101+
'matrix_ids' => 'matrix_id',
102+
'oxen' => 'ox',
103+
'aliases' => 'alias',
104+
'octupus' => 'octupus',
105+
'shoes' => 'shoe',
106+
'buses' => 'bus',
107+
'mice' => 'mouse',
108+
'movies' => 'movie',
109+
'series' => 'series',
110+
'hives' => 'hive',
111+
'lives' => 'life',
112+
'analyses' => 'analysis',
113+
'men' => 'man',
114+
'people' => 'person',
115+
'children' => 'child',
116+
'statuses' => 'status',
117+
'news' => 'news',
118+
'us' => 'us',
119+
'tests' => 'test',
120+
'queries' => 'query',
121+
'dogs' => 'dog',
122+
'cats' => 'cat',
123+
'families' => 'family',
124+
'countries' => 'country',
98125
];
99126

100127
foreach ($strings as $pluralizedString => $singularizedString) {

0 commit comments

Comments
 (0)