Uploaded image for project: 'named-regexp'
  1. REGEX-20

Named group index is incorrect after parens in a character class

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.1.2, 0.1.3, 0.1.4, 0.1.5, 0.1.6, 0.1.7, 0.1.8, 0.1.9, 0.1.10, 0.2.1
    • Fix Version/s: 0.2.2
    • Labels:
      None

      Description

      johnlcox@github writes:

      Parenthesis in a character class don't need to be escaped in a regex string. The Pattern#countOpenParens function does not account for this, and will count parenthesis in a character class as a group. This leads to the index being off for all named groups following the character class.

      Here is a unit test that will fail due to this:

      @Test
      public void testIndexOfNamedGroupAfterNonEscapedParenInCharacterClass() {
          Pattern p = Pattern.compile("(a)(?<foo>[()])(?:c)(?<named>x)");
          assertEquals(2, p.indexOf("named"));
      }

        Attachments

          Issue links

            Activity

              People

              • Assignee:
                tony19 TonyT
                Reporter:
                tony19 TonyT
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 2 hours
                  2h

                    Who's Looking?