You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2022/07/12 22:12:35 UTC

[groovy] branch GROOVY_4_0_X updated: GROOVY-10681: Groovysh doesn't handle multiline strings with """ or ''' correctly

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
     new 04e2764c7f GROOVY-10681: Groovysh doesn't handle multiline strings with """ or ''' correctly
04e2764c7f is described below

commit 04e2764c7f98f0a9d593d40e06379f0034aa2250
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon Jul 11 21:53:24 2022 +1000

    GROOVY-10681: Groovysh doesn't handle multiline strings with """ or ''' correctly
---
 .../main/groovy/org/apache/groovy/groovysh/Groovysh.groovy |  8 ++++----
 .../groovy/org/apache/groovy/groovysh/GroovyshTest.groovy  | 14 ++++++++++++++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy
index afefc00dad..2fbcd6548a 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy
@@ -246,10 +246,10 @@ class Groovysh extends Shell {
     private boolean isIncompleteCaseOfAntlr4(MultipleCompilationErrorsException t) {
         // TODO antlr4 parser errors pop out here - can we rework to be like antlr2?
         (
-                t.message.contains('Unexpected input:') && !(
-                            t.message.contains('Unexpected input: \'}\'')
-                        || t.message.contains('Unexpected input: \')\'')
-                        || t.message.contains('Unexpected input: \']\'')
+                (t.message.contains('Unexpected input: ') || t.message.contains('Unexpected character: ')) && !(
+                            t.message.contains("Unexpected input: '}'")
+                        || t.message.contains("Unexpected input: ')'")
+                        || t.message.contains("Unexpected input: ']'")
                 )
         )
     }
diff --git a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy
index 316ba88cfe..504f3b123e 100644
--- a/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy
+++ b/subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy
@@ -152,6 +152,20 @@ class GroovyshTest extends GroovyTestCase {
         assert mockOut.toString().contains('true')
     }
 
+    void testIncompleteMultilineSingleQuoteString() {
+        Groovysh groovysh = createGroovysh()
+        groovysh.execute("hw = '''Hello")
+        groovysh.execute("World!'''")
+        assert mockOut.toString().contains('lo\nWo')
+    }
+
+    void testIncompleteMultilineDoubleQuoteString() {
+        Groovysh groovysh = createGroovysh()
+        groovysh.execute('hw = """Hello')
+        groovysh.execute('World!"""')
+        assert mockOut.toString().contains('lo\nWo')
+    }
+
     void testMissingPropertyExpr() {
         Groovysh groovysh = createGroovysh()
         // this is a special case, e.g. happens for Gradle DefaultExtraPropertiesExtension