Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Str trim methods #50822

Merged
merged 8 commits into from
Apr 1, 2024
Merged

Conversation

patrickomeara
Copy link
Contributor

The native methods trim(), ltrim() and rtrim() don't remove the unicode whitecode character NBSP.

Str::squish() removes these characters, as does TrimStrings middleware.

This PR adds trim(), ltrim() and rtrim() static methods to the Str helper, and also uses these methods in the corresponding Stringable calls.

Note: For reviewers the whitespace characters don't show up in the web UI.

Test screenshots attached to show them.

image image image

@patrickomeara patrickomeara changed the title Str trim methods [11.x] Str trim methods Mar 28, 2024
@patrickomeara
Copy link
Contributor Author

patrickomeara commented Mar 29, 2024

An update here. The TrimStrings middleware handles binary data by using the native method when preg_replace returns null. I have implemented this behaviour in the new methods and also added the changes from @dasundev's #50832

@taylorotwell
Copy link
Member

@patrickomeara why is the white space removed by trim different from the regex used by ltrim and rtrim?

@patrickomeara
Copy link
Contributor Author

@taylorotwell The whitespace characters are the same, ltrim removes it from the beginning ^, and rtrim from the end $

image

@taylorotwell
Copy link
Member

Got it. Thanks!

@taylorotwell taylorotwell merged commit 4f6088b into laravel:11.x Apr 1, 2024
28 checks passed
@patrickomeara patrickomeara deleted the str-trim-methods branch April 2, 2024 13:50
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.

None yet

2 participants