rspec/rules/S5856/java/rule.adoc

26 lines
554 B
Plaintext
Raw Normal View History

include::../description.adoc[]
2021-04-28 16:49:39 +02:00
To match a literal string, rather than a regular expression, either all special characters should be escaped or the ``++Pattern.LITERAL++`` flag or methods that don't use regular expressions should be used.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
Pattern.compile("([");
str.matches("([");
str.replaceAll("([", "{");
str.matches("(\\w+-(\\d+)");
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
Pattern.compile("\\(\\[");
Pattern.compile("([", Pattern.LITERAL);
str.equals("([");
str.replace("([", "{");
str.matches("(\\w+)-(\\d+)");
----