You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Charlie Hubbard (Jira)" <ji...@apache.org> on 2022/05/20 16:05:00 UTC

[jira] [Created] (GROOVY-10634) Regular expressions cause groovysh 3.0.10 to crash

Charlie Hubbard created GROOVY-10634:
----------------------------------------

             Summary: Regular expressions cause groovysh 3.0.10 to crash
                 Key: GROOVY-10634
                 URL: https://issues.apache.org/jira/browse/GROOVY-10634
             Project: Groovy
          Issue Type: Bug
          Components: Groovy Console
    Affects Versions: 3.0.10
         Environment: Groovy Shell (3.0.10, JVM: 17.0.2)
Type ':help' or ':h' for help.
---------------------------------------------------------------------------
groovy:000> 
            Reporter: Charlie Hubbard
         Attachments: regex-matcher-group-4.txt, regex-matcher-group.txt, regular-expression-parsing-exception.txt

Running some of these expressions in groovysh will crash the shell.  The expectation is the print the exception to the console, and return to the next prompt without exiting the shell. (see attached for stack trace regular-expression-parsing-exception.txt).
{code:java}
groovy:000> "billy-bob.7866@aol.info.co".matches(/^([a-zA-Z0-9_-.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/) {code}
This however, will NOT crash it (notice the escaping for the hyphen in the first [] expression):
{code:java}
groovy:000> "billy-bob.7866@aol.info.co".matches(/^([a-zA-Z0-9_\-.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/) {code}
This will also crash it (stacktrace regex-matcher-group.txt):
{code:java}
groovy:000> m = (~/^((\d{4})(\s|-)?){4}$/).matcher( "4199 6238 0343 4807" )
===> java.util.regex.Matcher[pattern=^((\d{4})(\s|-)?){4}$ region=0,19 lastmatch=]
groovy:000> m.group(0) {code}
If you don't call `.matches()` before calling `.group()` then it will produce the crash.  However, if you do call `.matches()` the the following will crash it (stacktrace regex-matcher-group-4.txt):
{code:java}
groovy:000> m = (~/^((\d{4})(\s|-)?){4}$/).matcher( "4199 6238 0343 4807" )
===> java.util.regex.Matcher[pattern=^((\d{4})(\s|-)?){4}$ region=0,19 lastmatch=]
groovy:000> m.matches()
===> true
groovy:000> m.group(0)
===> 4199 6238 0343 4807
groovy:000> m.group(1)
===> 4807
groovy:000> m.group(2)
===> 4807
groovy:000> m.group(3)
===> 
groovy:000> m.group(4)
ERROR java.lang.IndexOutOfBoundsException: {code}



--
This message was sent by Atlassian Jira
(v8.20.7#820007)