groovy
  1. groovy
  2. GROOVY-3287

Implement workaround for JDK 1.4 String.replaceAll bug.

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.6-rc-2, 1.5.8
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      There is a bug in JDK 1.4's String.replaceAll in which quoted (\Q..\E) patterns that contain a backslash are not matched correctly.

      This should work, but does not in JDK 1.4 (JDK 1.5 is OK):

      assert "axa".equals("a\\a".replaceAll("\\Q\\\\E", "x"))
      

      The workaround is to have RegexUtils.quote not put backslashes inside the quote, but instead escape out of the quote and use a backslash to escape the backslash.

      So this does work in JDK 1.4 (and JDK 1.5 too of course):

      assert "axa".equals("a\\a".replaceAll("\\Q\\E\\\\\\Q\\E", "x"))
      

        Issue Links

          Activity

          Hide
          Jim White added a comment -

          The test case is:

          assert 'a\\a'.replace('\\', 'x') == 'axa'
          

          It is in groovy.StringTest.testReplace.

          Show
          Jim White added a comment - The test case is: assert 'a\\a'.replace('\\', 'x') == 'axa' It is in groovy.StringTest.testReplace .

            People

            • Assignee:
              Jim White
              Reporter:
              Jim White
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: