freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [2/2] freemarker git commit: FREEMARKER-109: In JSP TLD-s, line breaks inside a function parameter lists have caused IllegalArgumentException Invalid function signature.
Date Tue, 27 Nov 2018 19:38:39 GMT
FREEMARKER-109: In JSP TLD-s, line breaks inside a function parameter lists have caused IllegalArgumentException
Invalid function signature.


Project: http://git-wip-us.apache.org/repos/asf/freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/freemarker/commit/022714ad
Tree: http://git-wip-us.apache.org/repos/asf/freemarker/tree/022714ad
Diff: http://git-wip-us.apache.org/repos/asf/freemarker/diff/022714ad

Branch: refs/heads/2.3-gae
Commit: 022714ad67a46cb552e480b958550c2a77e07480
Parents: db4cb24
Author: ddekany <ddekany@apache.org>
Authored: Tue Nov 27 20:38:25 2018 +0100
Committer: ddekany <ddekany@apache.org>
Committed: Tue Nov 27 20:38:25 2018 +0100

----------------------------------------------------------------------
 .../freemarker/ext/jsp/TaglibMethodUtil.java    | 11 +++--
 src/manual/en_US/book.xml                       | 10 +++-
 .../java/freemarker/ext/jsp/TLDParsingTest.java | 52 ++++++++++++++------
 .../freemarker/ext/jsp/TLDParsingTest.tld       | 12 +++++
 4 files changed, 63 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/freemarker/blob/022714ad/src/main/java/freemarker/ext/jsp/TaglibMethodUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/jsp/TaglibMethodUtil.java b/src/main/java/freemarker/ext/jsp/TaglibMethodUtil.java
index 8ce1b05..ab1effb 100644
--- a/src/main/java/freemarker/ext/jsp/TaglibMethodUtil.java
+++ b/src/main/java/freemarker/ext/jsp/TaglibMethodUtil.java
@@ -33,7 +33,7 @@ final class TaglibMethodUtil {
     }
 
     private static final Pattern FUNCTION_SIGNATURE_PATTERN = 
-            Pattern.compile("^([\\w\\.]+(\\s*\\[\\s*\\])?)\\s+([\\w]+)\\s*\\((.*)\\)$");
+            Pattern.compile("^([\\w\\.]+(\\s*\\[\\s*\\])?)\\s+(\\w+)\\s*\\((.*)\\)$", Pattern.DOTALL);
     private static final Pattern FUNCTION_PARAMETER_PATTERN = 
             Pattern.compile("^([\\w\\.]+)(\\s*\\[\\s*\\])?$");
 
@@ -46,12 +46,13 @@ final class TaglibMethodUtil {
      * @param signature Java Server Page (TM) Specification compliant function signature
string.
      * @return method if found.
      */
-    public static Method getMethodByFunctionSignature(Class clazz, String signature)
+    static Method getMethodByFunctionSignature(Class clazz, String signature)
             throws SecurityException, NoSuchMethodException, ClassNotFoundException {
         Matcher m1 = FUNCTION_SIGNATURE_PATTERN.matcher(signature);
 
         if (!m1.matches()) {
-            throw new IllegalArgumentException("Invalid function signature.");
+            throw new IllegalArgumentException("Invalid function signature (doesn't match
this pattern: "
+                    + FUNCTION_SIGNATURE_PATTERN + ")");
         }
 
             String methodName = m1.group(3);
@@ -72,9 +73,9 @@ final class TaglibMethodUtil {
                 for (int i = 0; i < paramsArray.length; i++) {
                     token = paramsArray[i].trim();
                     m2 = FUNCTION_PARAMETER_PATTERN.matcher(token);
-
                     if (!m2.matches()) {
-                        throw new IllegalArgumentException("Invalid argument signature: '"
+ token + "'.");
+                        throw new IllegalArgumentException("Invalid argument signature (doesn't
match pattern " +
+                                FUNCTION_PARAMETER_PATTERN + "): " + token);
                     }
 
                     paramType = m2.group(1);

http://git-wip-us.apache.org/repos/asf/freemarker/blob/022714ad/src/manual/en_US/book.xml
----------------------------------------------------------------------
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index 1ea161b..e774e8c 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -30,7 +30,7 @@
 
     <titleabbrev>Manual</titleabbrev>
 
-    <productname>Freemarker 2.3.28</productname>
+    <productname>Freemarker 2.3.29</productname>
   </info>
 
   <preface role="index.html" xml:id="preface">
@@ -27634,6 +27634,14 @@ TemplateModel x = env.getVariable("x");  // get variable x</programlisting>
           <itemizedlist>
             <listitem>
               <para><link
+              xlink:href="https://issues.apache.org/jira/browse/FREEMARKER-109">FREEMARKER-109</link>:
+              In JSP TLD-s, line breaks inside a function parameter lists have
+              caused <literal>IllegalArgumentException</literal>
+              <quote>Invalid function signature</quote>.</para>
+            </listitem>
+
+            <listitem>
+              <para><link
               xlink:href="https://issues.apache.org/jira/browse/FREEMARKER-104">FREEMARKER-104</link>:
               More helpful log and error messages (especially, no
               <literal>NullPointerException</literal> cause exception logged

http://git-wip-us.apache.org/repos/asf/freemarker/blob/022714ad/src/test/java/freemarker/ext/jsp/TLDParsingTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/ext/jsp/TLDParsingTest.java b/src/test/java/freemarker/ext/jsp/TLDParsingTest.java
index ab45f07..37d2cb3 100644
--- a/src/test/java/freemarker/ext/jsp/TLDParsingTest.java
+++ b/src/test/java/freemarker/ext/jsp/TLDParsingTest.java
@@ -41,9 +41,10 @@ import org.xml.sax.XMLReader;
 
 import freemarker.ext.beans.BeansWrapper;
 import freemarker.ext.beans.BeansWrapperBuilder;
+import freemarker.template.SimpleNumber;
 import freemarker.template.SimpleScalar;
 import freemarker.template.TemplateMethodModelEx;
-import freemarker.template.TemplateModel;
+import freemarker.template.TemplateNumberModel;
 import freemarker.template.TemplateScalarModel;
 import freemarker.template.Version;
 
@@ -79,21 +80,36 @@ public class TLDParsingTest {
         assertTrue(tldParser.getListeners().get(0) instanceof ExampleContextListener);
 
         Map tagsAndFunctions = tldParser.getTagsAndFunctions();
-        assertEquals(4, tagsAndFunctions.size());
-
-        JspTagModelBase tag = (JspTagModelBase) tagsAndFunctions.get("setStringAttributeTag");
-        assertNotNull(tag);
-        tag = (JspTagModelBase) tagsAndFunctions.get("setStringAttributeTag2");
-        assertNotNull(tag);
-
-        TemplateMethodModelEx function = (TemplateMethodModelEx) tagsAndFunctions.get("toUpperCase");
-        assertNotNull(function);
-        TemplateScalarModel result = (TemplateScalarModel) function.exec(Arrays.asList(new
TemplateModel [] { new SimpleScalar("abc") }));
-        assertEquals("ABC", result.getAsString());
-        function = (TemplateMethodModelEx) tagsAndFunctions.get("toUpperCase2");
-        assertNotNull(function);
-        result = (TemplateScalarModel) function.exec(Arrays.asList(new TemplateModel [] {
new SimpleScalar("abc") }));
-        assertEquals("ABC", result.getAsString());
+        assertEquals(5, tagsAndFunctions.size());
+
+        {
+            JspTagModelBase tag = (JspTagModelBase) tagsAndFunctions.get("setStringAttributeTag");
+            assertNotNull(tag);
+            tag = (JspTagModelBase) tagsAndFunctions.get("setStringAttributeTag2");
+            assertNotNull(tag);
+        }
+
+        {
+            TemplateMethodModelEx function = (TemplateMethodModelEx) tagsAndFunctions.get("toUpperCase");
+            assertNotNull(function);
+            TemplateScalarModel result = (TemplateScalarModel) function.exec(Arrays.asList(new
SimpleScalar("abc")));
+            assertEquals("ABC", result.getAsString());
+        }
+
+        {
+            TemplateMethodModelEx function = (TemplateMethodModelEx) tagsAndFunctions.get("toUpperCase2");
+            assertNotNull(function);
+            TemplateScalarModel result = (TemplateScalarModel) function.exec(Arrays.asList(new
SimpleScalar("abc")));
+            assertEquals("ABC", result.getAsString());
+        }
+
+        {
+            TemplateMethodModelEx function = (TemplateMethodModelEx) tagsAndFunctions.get("add3");
+            assertNotNull(function);
+            TemplateNumberModel result = (TemplateNumberModel) function.exec(Arrays.asList(
+                    new SimpleNumber(1), new SimpleNumber(2), new SimpleNumber(3)));
+            assertEquals(6, result.getAsNumber());
+        }
     }
 
     public static class StringFunctions {
@@ -104,6 +120,10 @@ public class TLDParsingTest {
         public static String toUpperCase(String source) {
             return source.toUpperCase();
         }
+
+        public static int add3(int x, int y, int z) {
+            return x + y + z;
+        }
     }
     
     public static class SetStringAttributeTag extends TagSupport {

http://git-wip-us.apache.org/repos/asf/freemarker/blob/022714ad/src/test/resources/freemarker/ext/jsp/TLDParsingTest.tld
----------------------------------------------------------------------
diff --git a/src/test/resources/freemarker/ext/jsp/TLDParsingTest.tld b/src/test/resources/freemarker/ext/jsp/TLDParsingTest.tld
index 1f7e049..52e277b 100644
--- a/src/test/resources/freemarker/ext/jsp/TLDParsingTest.tld
+++ b/src/test/resources/freemarker/ext/jsp/TLDParsingTest.tld
@@ -86,4 +86,16 @@
     <function-signature>String toUpperCase(java.lang.String)</function-signature>
   </function>
 
+  <function>
+    <name>add3</name>
+    <function-class>freemarker.ext.jsp.TLDParsingTest$StringFunctions</function-class>
+    <function-signature>
+      int  add3 (
+        int  ,
+        int,
+        int
+      )
+    </function-signature>
+  </function>
+
 </taglib>


Mime
View raw message