
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
64 lines
1.2 KiB
Plaintext
64 lines
1.2 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Using certain features of regular expressions, it is possible to create regular expressions that can never match or contain subpatterns that can never match. Since a pattern or sub-pattern that can never match any input is pointless, this is a sign that the pattern does not work as intended and needs to be fixed.
|
|
|
|
|
|
This rule finds some such regular expressions and subpatterns, specifically ones that meet one of the following conditions:
|
|
|
|
|
|
* Beginning- and end-of-line/input boundaries appearing in a position where they can never match (e.g. an end-of-input marker being followed by other characters)
|
|
* A back reference refers to a capturing group that will never be matched before the back reference
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
==== Boundaries
|
|
|
|
[source,java]
|
|
----
|
|
$[a-z]*^
|
|
----
|
|
|
|
==== Backreference
|
|
|
|
[source,java]
|
|
----
|
|
\1(.)
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
==== Boundaries
|
|
|
|
[source,java]
|
|
----
|
|
^[a-z]*$
|
|
----
|
|
|
|
==== Backreference
|
|
|
|
[source,java]
|
|
----
|
|
(.)\1
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Remove this sub-pattern or rewrite the regex.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
The failing sub-pattern
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|