rspec/rules/S5856/php/rule.adoc

28 lines
589 B
Plaintext
Raw Permalink Normal View History

== Why is this an issue?
include::../description.adoc[]
To match a literal string, rather than a regular expression, either all special characters should be escaped or methods that dont use regular expressions should be used.
=== Noncompliant code example
2022-02-04 17:28:24 +01:00
[source,php]
----
preg_match("/([/", $input);
preg_replace("/[/", "{", $input);
preg_replace("/(\\w+-(\\d+)/", "1234", $input);
----
=== Compliant solution
2022-02-04 17:28:24 +01:00
[source,php]
----
preg_match("/\\(\\[/", $input);
str_replace("([", "{", $input);
preg_replace("/(\\w+)-(\\d+)/", "1234", $input);
----
2023-03-22 15:25:58 +01:00
include::../rspecator.adoc[]