Skip to content

fix(Helpers): fix matrix and vertex regex grouping in plural() - #10782

Open
banghamid wants to merge 1 commit into
codeigniter4:developfrom
banghamid:fix/inflector-plural-matrix-regex
Open

banghamid wants to merge 1 commit into
codeigniter4:developfrom
banghamid:fix/inflector-plural-matrix-regex

Conversation

@banghamid

@banghamid banghamid commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Description
In inflector_helper.php, the plural rule for matrix, vertex, and index was written as:

'/(matr|vert|ind)ix|ex$/' => '\1ices',

Due to operator precedence, this was evaluated as ((matr|vert|ind)ix) | (ex$). Consequently:

  1. (matr|vert|ind)ix lacked an end-of-string anchor $, improperly matching occurrences before the end of strings (e.g. matrix_id became matrices_id).
  2. Any word ending in ex$ matched the second branch where group \1 was not captured (empty string), corrupting words like complex into complices and sex into sices instead of falling through to the /(x|ch|ss|sh)$/ rule.

This PR wraps the alternative endings in a non-capturing group (?:ix|ex)$, adds test cases for vertex, index, complex, sex, and matrix_id, and adds a changelog entry in docs/changelogs/v4.7.7.md.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@carson-codeigniter4 carson-codeigniter4 Bot added the bug Verified issues on the current code behavior or pull requests that will fix them label Nov 18, 2026
Comment thread system/Helpers/inflector_helper.php Resolved
Fix regex grouping and missing end-of-string anchor in plural() rule for matrix, vertex, and index. Expand plural() and singular() to support other words ending in ix/ex taking ices (apex, appendix, codex, cortex, latex, murex, vortex) while preserving standard -es pluralization for words like complex, sex, duplex, and annex.
@banghamid
banghamid force-pushed the fix/inflector-plural-matrix-regex branch from aecc927 to 8da68f5 Compare November 19, 2026 02:09
@banghamid

Copy link
Copy Markdown
Contributor Author

Updated! I've expanded both plural() and singular() to support those loanwords (apex, appendix, codex, cortex, latex, murex, vortex), while ensuring words like complex, sex, annex, duplex, and ex still resolve with standard -es. Test cases have been added to cover both directions.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants