Skip to content

Conversation

@restuff
Copy link
Contributor

@restuff restuff commented Jan 17, 2023

It is always a good practice to avoid or at least minimize the usage of unescaped non-ascii characters in source code, especially if they are invisible characters.

#41949 introduced an addition to TrimStrings middleware's regex to filter out "Zero Width No-Break Space" (\x{FEFF}) characters, however it was implemented as a raw unescaped invisible character in the source code.

image

#44906 added one more invisible character "Zero Width Space" (\x{200B}) to the same regex.

image

However, these symbols aren't visible in GitHub diff

image

as well as in some text editors like Notepad++ (even with Show All Characters option turned on)

image

This PR adds more readability to the source code by replacing those invisible characters in both places where they are used with their counterpart Unicode regex notations without affecting the functionality.

\Illuminate\Foundation\Http\Middleware::transform():
image

\Illuminate\Support\Str::squish():
image

There's no need to modify corresponding tests that use "real-life" unescaped raw invisible characters as functionality hasn't changed, however there were added some spelling corrections.

@restuff restuff changed the title Replace raw invisible characters in regex expressions with counterpar… [9.x] Replace raw invisible characters in regex expressions with counterpar… Jan 17, 2023
@restuff restuff changed the title [9.x] Replace raw invisible characters in regex expressions with counterpar… [9.x] Replace raw invisible characters in regex expressions with counterpart Unicode regex notations Jan 17, 2023
@taylorotwell taylorotwell merged commit e4f05eb into laravel:9.x Jan 18, 2023
@taylorotwell
Copy link
Member

Thanks

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.

2 participants