rspec/rules/S5867/php/rule.adoc

25 lines
750 B
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

== Why is this an issue?
When using metacharacters like `\w` without the Unicode flag or when using hard-coded character classes like `[a-zA-Z]`,
letters outside of the ASCII range, such as umlauts, accented letters, or letters from non-Latin languages, wont be matched.
This may cause code to incorrectly handle input containing such letters.
To correctly handle non-ASCII input, it is recommended to use the Unicode flag `\u` or Unicode character properties like `\p{L}`.
=== Noncompliant code example
[source,php]
----
preg_match("/[a-zA-Z]/", "ö"); // returns 0
preg_match("/\w/", "ö"); // returns 0
----
=== Compliant solution
[source,php]
----
preg_match("/\w/u", "ö"); // returns 1
preg_match("/\p{L}/", "ö"); // return 1
----