Repository navigation
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 nativeltrim(), 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: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/phpunitis green, phpcs is clean, and PHPStan reports no errors locally. The PHPStan job in CI fails on4.x-devas well (mb_trimand the other PHP 8.4 polyfill functions are not found), and #66 fixes that.Documentation Changes Required
None. No docs page on
4.x-devdescribesucwords(). The owner's docs PR #72 only shows it in theStringHelperexample list, which stays correct.🤖 Generated with Claude Code