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 2020/04/07 03:23:28 UTC

[groovy] 01/02: GROOVY-9194: Groovy fails when a script starts with a #

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

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

commit 64c94a28a80b6b008027fb1f6d553f6ba289fd7a
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Apr 7 13:18:48 2020 +1000

    GROOVY-9194: Groovy fails when a script starts with a #
---
 src/main/java/org/codehaus/groovy/ast/ModuleNode.java | 6 +++---
 src/test/org/codehaus/groovy/ast/ModuleNodeTest.java  | 9 ++++++++-
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/ModuleNode.java b/src/main/java/org/codehaus/groovy/ast/ModuleNode.java
index 4e1376e..f305aea 100644
--- a/src/main/java/org/codehaus/groovy/ast/ModuleNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/ModuleNode.java
@@ -408,12 +408,12 @@ public class ModuleNode extends ASTNode implements Opcodes {
             URI uri = new URI(answer);
             String path = uri.getPath();
             String schemeSpecific = uri.getSchemeSpecificPart();
-            if (path!=null) {
+            if (path != null && !path.isEmpty()) {
                 answer = path;
-            } else if (schemeSpecific!=null) {
+            } else if (schemeSpecific != null && !schemeSpecific.isEmpty()) {
                 answer = schemeSpecific;
             }
-        } catch (URISyntaxException e) {}
+        } catch (URISyntaxException ignore) {}
         // let's strip off everything after the last '.'
         int slashIdx = answer.lastIndexOf('/');
         int separatorIdx = answer.lastIndexOf(File.separatorChar);
diff --git a/src/test/org/codehaus/groovy/ast/ModuleNodeTest.java b/src/test/org/codehaus/groovy/ast/ModuleNodeTest.java
index 64aa295..d816156 100644
--- a/src/test/org/codehaus/groovy/ast/ModuleNodeTest.java
+++ b/src/test/org/codehaus/groovy/ast/ModuleNodeTest.java
@@ -38,7 +38,14 @@ public class ModuleNodeTest extends TestParserSupport {
         assertEquals("Number of classes", 1, classes.size());
 
         ClassNode classNode = (ClassNode) classes.get(0);
-
         assertEquals("Class name", "Cheese", classNode.getName());
     }
+
+    // GROOVY-9194
+    public void testScriptStartingWithHash() {
+        ModuleNode mn = new ModuleNode((CompileUnit) null);
+        mn.setDescription("#script.groovy");
+        ClassNode cn = mn.getScriptClassDummy();
+        assertEquals("Dummy class name should not be empty", "#script", cn.getName());
+    }
 }