Skip to content

[4.x] Fix StringHelper::ucwords() after form feed separators - #76

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-ucwords-whitespace
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-ucwords-whitespace

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

StringHelper::ucwords() treats form feeds (\f, \x0c) as word separators, but the callback removed the leading whitespace of each match with the native ltrim(), which does not strip \f. substr_replace() then overwrote the form feed instead of the first letter, so the first letter of the word was duplicated:

StringHelper::ucwords("a\fbc def"); // "A\fBbc Def" instead of "A\fBc Def"

The pattern now captures the rest of the word as well, and the callback builds the result from the capture groups: separators, the uppercased first character, then the rest of the word. Vertical tabs were not affected, because ltrim() strips \x0b, but they now take the same code path.

Testing Instructions

New cases in StringHelperTest::seedTestUcwords: a form feed separator, a vertical tab separator, and a string with leading whitespace and several separators in a row. The form feed cases fail before the change and pass after it. vendor/bin/phpunit is green, phpcs is clean, and PHPStan reports no errors locally. The PHPStan job in CI fails on 4.x-dev as well (mb_trim and the other PHP 8.4 polyfill functions are not found), and #66 fixes that.

Documentation Changes Required

None. No docs page on 4.x-dev describes ucwords(). The owner's docs PR #72 only shows it in the StringHelper example list, which stays correct.

🤖 Generated with Claude Code

The pattern treats form feeds as word separators, but the callback
removed the leading whitespace with ltrim(), which does not strip
"\f". substr_replace() then overwrote the form feed instead of the first
letter, so ucwords("a\fbc") returned "A\fBbc".

Build the result from the capture groups instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant