Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-5840

Regex patterns and their sub-patterns should not always fail

    XMLWordPrintable

    Details

    • Type: Bug Detection
    • Status: Deprecated
    • Resolution: Unresolved
    • Labels:
      None
    • Message:
      Remove this sub-pattern or rewrite the regex.
    • Highlighting:
      Hide

      The failing sub-pattern

      Show
      The failing sub-pattern
    • Default Severity:
      Critical
    • Impact:
      High
    • Likelihood:
      Low
    • Covered Languages:
      Java
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      10min
    • Analysis Level:
      Syntactic Analysis
    • Analysis Scope:
      Main Sources, Test Sources

      Description

      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

      $[a-z]*^
      

      Backreference

      \1(.)
      

      Compliant Solution

      Boundaries

      ^[a-z]*$
      

      Backreference

      (.)\1
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              sebastian.hungerecker Sebastian Hungerecker
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: