Skip to content

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

Closed
@pmishev

Description

@pmishev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugFormGood first issueIdeal for your first contribution! (some Symfony experience may be required)Help wantedIssues and PRs which are looking for volunteers to complete them.Status: Needs Review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions