groovy
  1. groovy
  2. GROOVY-3536

multi / single line regular expression infinite loop

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.6.2
    • Fix Version/s: None
    • Component/s: regular expressions
    • Labels:
      None
    • Environment:
      windows xp sp3 x64
    • Number of attachments :
      0

      Description

      //groovy version 1.6.2
      //this script seems to go on an infinite loop in the last line 
      
      def str = '''ID_843110_DATE
      2008-08-26 02:53:25
      ID_843110_SRC
      This is a test
      ID_843110_TRG
      Aceasta este o incercare
      '''
      
      def id = 843110
      
      def m = str =~ /(?s)^ID_($id)_DATE\n.*\nID_($id)_SRC\n(.*\n)+ID_($id)_TRG\n(.*\n)+/
      
      m.each { println it }
       
      m = str =~ /(?s)^ID_($id)_DATE\n.*\nID_($id)_SRC\n(.*)+ID_($id)_TRG\n(.*\n)+/
      
      m.each{ println it }
      

        Activity

        Hide
        Paul King added a comment -

        This is present in Java too:

        import java.util.regex.Matcher;
        import java.util.regex.Pattern;
        
        public class Main {
            public static void main(String[] args) {
                String str = "ID_843110_DATE\n" +
        "2008-08-26 02:53:25\n" +
        "ID_843110_SRC\n" +
        "This is a test\n" +
        "ID_843110_TRG\n" +
        "Aceasta este o incercare\n";
        
                int id = 843110;
        
                String regex = "(?s)^ID_(" + id + ")_DATE\\n.*\\nID_(" + id + ")_SRC\\n(.*)+ID_(" + id + ")_TRG\\n(.*\\n)+";
                Matcher m = Pattern.compile(regex).matcher(str);
                System.out.println("m.matches() = " + m.matches());
            }
        }
        

        And from looking at the Java bug database, it doesn't seem like Java tries to police such dangerous expressions, e.g.:
        http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4704828

        Show
        Paul King added a comment - This is present in Java too: import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main( String [] args) { String str = "ID_843110_DATE\n" + "2008-08-26 02:53:25\n" + "ID_843110_SRC\n" + "This is a test\n" + "ID_843110_TRG\n" + "Aceasta este o incercare\n" ; int id = 843110; String regex = "(?s)^ID_(" + id + ")_DATE\\n.*\\nID_(" + id + ")_SRC\\n(.*)+ID_(" + id + ")_TRG\\n(.*\\n)+" ; Matcher m = Pattern.compile(regex).matcher(str); System .out.println( "m.matches() = " + m.matches()); } } And from looking at the Java bug database, it doesn't seem like Java tries to police such dangerous expressions, e.g.: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4704828
        Hide
        blackdrag blackdrag added a comment -

        this means we should close the issue?

        Show
        blackdrag blackdrag added a comment - this means we should close the issue?
        Hide
        Paul King added a comment -

        Our options are:

        1. ignore the issue because Java does
        2. find a work around for the existing library (I can't think of one though)
        3. substitute a different library

        I guess I am in favor of the first of these so long as we document the kind of things to look out for that might cause grief with the current Java libraries and document how to use some of the other available libraries. I.e. change this from bug to documentation enhancement.

        Show
        Paul King added a comment - Our options are: ignore the issue because Java does find a work around for the existing library (I can't think of one though) substitute a different library I guess I am in favor of the first of these so long as we document the kind of things to look out for that might cause grief with the current Java libraries and document how to use some of the other available libraries. I.e. change this from bug to documentation enhancement.
        Hide
        Paul King added a comment -

        Closing for now unless a definite proposal is submitted. Users running into this issue will likely find this issue and deduce the problem, i.e. their incorrect usage of the underlying api.

        Show
        Paul King added a comment - Closing for now unless a definite proposal is submitted. Users running into this issue will likely find this issue and deduce the problem, i.e. their incorrect usage of the underlying api.

          People

          • Assignee:
            Paul King
            Reporter:
            Arun Ramakrishnan
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: