
In some cases, the `rule.adoc` at root of a rule is never included anywhere and thus is dead code. It's a maintenance cost by itself, but also it misses opportunities to inline code that seems used by two documents when in fact only one document is actually rendered. And this missed opportunity, in turn, stops us from applying the correct language tag on the code samples.
48 lines
1.5 KiB
Plaintext
48 lines
1.5 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Regular expressions are powerful but tricky, and even those long used to using them can make mistakes.
|
|
|
|
|
|
The following should not be used as regular expressions:
|
|
|
|
* ``++.++`` - matches any single character. Used in ``++replaceAll++``, it matches _everything_
|
|
* ``++|++`` - normally used as an option delimiter. Used stand-alone, it matches the space between characters
|
|
* ``++File.separator++`` - matches the platform-specific file path delimiter. On Windows, this will be taken as an escape character
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
String str = "/File|Name.txt";
|
|
|
|
String clean = str.replaceAll(".",""); // Noncompliant; probably meant to remove only dot chars, but returns an empty string
|
|
String clean2 = str.replaceAll("|","_"); // Noncompliant; yields _/_F_i_l_e_|_N_a_m_e_._t_x_t_
|
|
String clean3 = str.replaceAll(File.separator,""); // Noncompliant; exception on Windows
|
|
|
|
String clean4 = str.replaceFirst(".",""); // Noncompliant;
|
|
String clean5 = str.replaceFirst("|","_"); // Noncompliant;
|
|
String clean6 = str.replaceFirst(File.separator,""); // Noncompliant;
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Correct this regular expression.
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 6 Sep 2016, 09:36:35 Nicolas Peru wrote:
|
|
The empty character class [] won't be a compilable regexp in java.
|
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|