Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-3557

Rule S6001: Back references in regular expressions should only refer to capturing groups that are matched before the reference

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.10
    • Component/s: Rules
    • Labels:

      Description

      First visit all capturing groups to mark the backreferences reachable from it:

      visitCapturingGroup(group) {
        add group to the set of defined groups
        markBackReferences(group, group.continuation)
      }
      
      void markBackReferences(GroupTree group, AutomatonState s) {
        if s has already been visited (from this particular group):
          return
      
        if s is a backreference and its name or number matches that of group:
          add (BackRefereceTree) s to set of legal back references
        for succ in s.successors:
          markBackReferences(group, succ)
      }
      

      Afterwards visit all back references and check whether they're in the set of legal back references. If not, report an issue. Use the set of all defined groups to distinguish between references to groups that aren't defined at all vs. those that just haven't been defined yet.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Due:
                Created:
                Updated:
                Resolved: