2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-09-14 15:32:14 +02:00
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.
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-09-14 15:32:14 +02:00
2022-02-04 17:28:24 +01:00
[source,php]
2021-09-14 15:32:14 +02:00
----
preg_match("/([/", $input);
preg_replace("/[/", "{", $input);
preg_replace("/(\\w+-(\\d+)/", "1234", $input);
----
2023-05-03 11:06:20 +02:00
=== Compliant solution
2021-09-14 15:32:14 +02:00
2022-02-04 17:28:24 +01:00
[source,php]
2021-09-14 15:32:14 +02:00
----
preg_match("/\\(\\[/", $input);
str_replace("([", "{", $input);
preg_replace("/(\\w+)-(\\d+)/", "1234", $input);
----
2023-03-22 15:25:58 +01:00
include::../rspecator.adoc[]