rspec/rules/S5856/java/rule.adoc

29 lines
601 B
Plaintext
Raw Normal View History

include::../description.adoc[]
2021-04-28 16:49:39 +02:00
To match a literal string instead of a regular expression, either all special characters should be escaped, the `Pattern.LITERAL` flag or methods that don't use regular expressions should be used.
2021-04-28 16:49:39 +02:00
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
Pattern.compile("([");
str.matches("([");
str.replaceAll("([", "{");
str.matches("(\\w+-(\\d+)");
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
Pattern.compile("\\(\\[");
Pattern.compile("([", Pattern.LITERAL);
str.equals("([");
str.replace("([", "{");
str.matches("(\\w+)-(\\d+)");
----
2023-03-22 15:25:58 +01:00
include::../rspecator.adoc[]