28 lines
589 B
Plaintext
28 lines
589 B
Plaintext
== 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 don’t 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[]
|