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

[Forms] trim option is not removing UTF8 ZERO WIDTH SPACE (\xE2\x80\x8B) #39230

Open
pmishev opened this issue Nov 30, 2020 · 0 comments
Open

[Forms] trim option is not removing UTF8 ZERO WIDTH SPACE (\xE2\x80\x8B) #39230

pmishev opened this issue Nov 30, 2020 · 0 comments

Comments

@pmishev
Copy link

@pmishev pmishev commented Nov 30, 2020

Symfony version(s) affected: 4.4.16

Description
StringUtil::trim() is doing preg_replace('/^[\pZ\p{Cc}]+|[\pZ\p{Cc}]+$/u', '', $string) to trim strings, however this regex is missing ZERO WIDTH SPACE (\xE2\x80\x8B) characters.

How to reproduce
http://sandbox.onlinephpfunctions.com/code/5b72e8ff76c34a313c0f2799995f56e5993b6b60

Possible Solution

p{Cf} catches this character, but it also catches some soft-hyphen (https://en.wikipedia.org/wiki/Unicode_character_property). I don't think that should be a problem though.

I suggest the regex to be changed to preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $string).
Cc and Cf are the only categories with characters in the C group anyway.

@pmishev pmishev added the Bug label Nov 30, 2020
derrabus added a commit that referenced this issue Dec 8, 2020
…U+200B) and SOFT HYPHEN (U+00AD) (pmishev)

This PR was merged into the 4.4 branch.

Discussion
----------

[Form] Fixed StringUtil::trim() to trim ZERO WIDTH SPACE (U+200B) and SOFT HYPHEN (U+00AD)

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #39230 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT
<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/releases):
 - Always add tests and ensure they pass.
 - Never break backward compatibility (see https://symfony.com/bc).
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too.)
 - Features and deprecations must be submitted against branch 5.x.
-->

Commits
-------

258bea7 [Form] Fixed StringUtil::trim() to trim ZERO WIDTH SPACE (U+200B) and SOFT HYPHEN (U+00AD)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.