Skip to content

Fix camelize and upperCamelize for all-caps inputs#51

Merged
voku merged 5 commits intomasterfrom
copilot/fix-camelcase-all-caps-input
Apr 22, 2026
Merged

Fix camelize and upperCamelize for all-caps inputs#51
voku merged 5 commits intomasterfrom
copilot/fix-camelcase-all-caps-input

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 11, 2026

  • Inspect current dependency constraints and CI commands
  • Run baseline validation with current composer.json
  • Replace inline alias for voku/portable-utf8 with ~6.1.0
  • Run composer update to confirm dependency resolution
  • Run phpunit to verify no regressions
  • Run phpstan and confirm the same 6 pre-existing failures remain unrelated to this change
  • Store durable repo facts confirmed during validation

This change is Reviewable

Copilot AI linked an issue Apr 11, 2026 that may be closed by this pull request
When input contains delimiters (spaces, dashes, underscores), lowercase
the string before camelizing. This fixes all-caps inputs like 'FOO BAR'
producing 'fOOBAR' instead of the expected 'fooBar'.

Inputs without delimiters (e.g. 'ServeHTTP', 'CamelCase') are not
affected since their word boundaries are determined by case transitions.

Agent-Logs-Url: https://github.com/voku/Stringy/sessions/ef23f588-aedc-4674-b479-c81d993fcc79

Co-authored-by: voku <264695+voku@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bug with camelCase processing for all caps inputs Fix camelCase and upperCamelize for all-caps inputs Apr 11, 2026
Copilot finished work on behalf of voku April 11, 2026 21:05
Copilot AI requested a review from voku April 11, 2026 21:05
@voku voku marked this pull request as ready for review April 11, 2026 22:09
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 11, 2026

Coverage Status

coverage: 97.987%. remained the same — copilot/fix-camelcase-all-caps-input into master

@voku
Copy link
Copy Markdown
Owner

voku commented Apr 12, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the camelize and upperCamelize methods in src/Stringy.php to lowercase input strings containing delimiters before conversion, ensuring all-caps strings are handled correctly. New test cases have been added to verify this behavior with various delimiters and UTF-8 characters. Feedback suggests expanding the delimiter regex to include digits (\d) to align with word boundary definitions and adding the u modifier for proper UTF-8 support. Additionally, refactoring the duplicated preprocessing logic into a shared private helper method is recommended for better maintainability.

Comment thread src/Stringy.php Outdated
{
$str = $this->str;

if (\preg_match('/[-_\s]/', $str)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The regex used to detect delimiters is missing digits (\d), which are explicitly defined as word boundaries in the method's docstring ("capitalizes letters following digits..."). Without this, all-caps strings separated by numbers (e.g., 'API2URL') will not be lowercased and will return incorrect results like 'aPI2URL' instead of 'api2Url'.

Additionally, consider adding the u modifier to the regex for consistent UTF-8 support. Without it, \s only matches ASCII whitespace, which might lead to inconsistent behavior if the input contains multibyte whitespace characters (like an ideographic space U+3000) that the underlying str_camelize might otherwise treat as a delimiter.

        if (\preg_match('/[-_\s\d]/u', $str)) {

Comment thread src/Stringy.php Outdated
{
$str = $this->str;

if (\preg_match('/[-_\s]/', $str)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the camelize() method, this regex should include \d to correctly handle all-caps inputs containing numbers.

Also, note that this preprocessing logic is now identical in both camelize() and upperCamelize(). While out of scope for a quick fix, refactoring this into a shared private helper method would improve maintainability.

        if (\preg_match('/[-_\s\d]/u', $str)) {

- Expand delimiter regex to include digits (\d) and add u modifier for
  UTF-8 support, per code review feedback
- Add !has_lowercase() guard to avoid incorrectly lowercasing mixed-case
  inputs that happen to contain digits (e.g. 'StringWith1Number')
- Refactor duplicated preprocessing logic from camelize() and
  upperCamelize() into a private prepareStringForCamelization() helper
- Add API2URL test cases to verify all-caps digit-separated input

Agent-Logs-Url: https://github.com/voku/Stringy/sessions/2644a089-2d2a-45ba-8c08-2f959e048507

Co-authored-by: voku <264695+voku@users.noreply.github.com>
Copilot finished work on behalf of voku April 13, 2026 02:03
@voku
Copy link
Copy Markdown
Owner

voku commented Apr 18, 2026

@copilot the bug was fixed upstream, validat that and just keep the tests afterwards

- Revert src/Stringy.php to its original state (remove prepareStringForCamelization helper and the changes to camelize()/upperCamelize())
- Update composer.json to use portable-utf8 6.1.1 (aliased as 6.0.14 to satisfy transitive anti-xss constraint) which has the identical has_lowercase + delimiter-regex fix natively in str_camelize/str_upper_camelize
- Keep the test cases added for all-caps ASCII, UTF-8, and digit-delimited inputs

Agent-Logs-Url: https://github.com/voku/Stringy/sessions/50c08647-569d-4146-babb-8c10f05272db

Co-authored-by: voku <264695+voku@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Apr 18, 2026

@copilot the bug was fixed upstream, validat that and just keep the tests afterwards

Confirmed: portable-utf8 6.1.1 has the identical preg_match('/[-_\s\d]/u', $str) && !has_lowercase($str) check natively inside str_camelize and str_upper_camelize.

Reverted src/Stringy.php to its original state (no workaround) and updated composer.json to pull in 6.1.1 via an inline alias (6.1.1 as 6.0.14) that satisfies the transitive voku/anti-xss ~6.0.2 constraint. All test cases are kept and all 3704 tests pass (commit 910f7be).

Copilot AI changed the title Fix camelCase and upperCamelize for all-caps inputs Fix camelize and upperCamelize for all-caps inputs Apr 18, 2026
Copilot finished work on behalf of voku April 18, 2026 20:21
Copilot finished work on behalf of voku April 20, 2026 08:01
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/0ecf06e1-1f6a-4cd2-b0ec-899948adc157

Co-authored-by: voku <264695+voku@users.noreply.github.com>
Copilot finished work on behalf of voku April 22, 2026 01:39
@voku voku merged commit afb11b5 into master Apr 22, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug with camelCase and all caps inputs.

3 participants