rspec/rules/S5856/php/rule.adoc

28 lines
589 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?
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
[source,php]
----
preg_match("/([/", $input);
preg_replace("/[/", "{", $input);
preg_replace("/(\\w+-(\\d+)/", "1234", $input);
----
=== Compliant solution
[source,php]
----
preg_match("/\\(\\[/", $input);
str_replace("([", "{", $input);
preg_replace("/(\\w+)-(\\d+)/", "1234", $input);
----
include::../rspecator.adoc[]