Groovy
  1. Groovy
  2. GROOVY-3536

multi / single line regular expression infinite loop

    Details

    • Type: Bug Bug
    • Status: 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

      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

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        585d 5h 2m 1 Paul King 26/Dec/10 03:46
        Resolved Resolved Closed Closed
        20s 1 Paul King 26/Dec/10 03:47
        Mark Thomas made changes -
        Workflow jira [ 12970328 ] Default workflow, editable Closed status [ 12978104 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12732527 ] Default workflow, editable Closed status [ 12744365 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Paul King made changes -
        Assignee Paul King [ paulk ]
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Won't Fix [ 2 ]
        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.
        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
        Jochen Theodorou added a comment -

        this means we should close the issue?

        Show
        Jochen Theodorou added a comment - this means we should close the issue?
        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
        Paul King made changes -
        Field Original Value New Value
        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 }
        {code}
        //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 }
        {code}
        Arun Ramakrishnan created issue -

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development