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] Include all invisible characters in Str::trim #54281

Draft
wants to merge 2 commits into
base: 11.x
Choose a base branch
from

Conversation

laserhybiz
Copy link

This PR adds all invisible characters to the Str::trim method. Currently, it only includes ZERO WIDTH NO-BREAK SPACE, ZERO WIDTH SPACE, and LEFT-TO-RIGHT MARK (introduced in #50822).

Comment on lines 1523 to 1525
$trimDefaultCharacters = " \n\r\t\v\0";

return preg_replace('~^[\s\x{FEFF}\x{200B}\x{200E}'.$trimDefaultCharacters.']+|[\s\x{FEFF}\x{200B}\x{200E}'.$trimDefaultCharacters.']+$~u', '', $value) ?? trim($value);
$invisibleCharacters = '\x{0009}\x{0020}\x{00A0}\x{00AD}\x{034F}\x{061C}\x{115F}\x{1160}\x{17B4}\x{17B5}\x{180E}\x{2000}\x{2001}\x{2002}\x{2003}\x{2004}\x{2005}\x{2006}\x{2007}\x{2008}\x{2009}\x{200A}\x{200B}\x{200C}\x{200D}\x{200E}\x{200F}\x{202F}\x{205F}\x{2060}\x{2061}\x{2062}\x{2063}\x{2064}\x{2065}\x{206A}\x{206B}\x{206C}\x{206D}\x{206E}\x{206F}\x{3000}\x{2800}\x{3164}\x{FEFF}\x{FFA0}\x{1D159}\x{1D173}\x{1D174}\x{1D175}\x{1D176}\x{1D177}\x{1D178}\x{1D179}\x{1D17A}\x{E0020}';
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason, both these variables are redefined three times instead of making them a class constant?

@taylorotwell
Copy link
Member

Can this be a constant or something?

@taylorotwell taylorotwell marked this pull request as draft January 21, 2025 14:56
@laserhybiz
Copy link
Author

@taylorotwell updated

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.

3 participants