You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2016/12/01 15:29:28 UTC
svn commit: r1772229 - in /tomcat/trunk: java/org/apache/el/parser/
test/org/apache/el/ test/webapp/WEB-INF/ test/webapp/bug6nnnn/ webapps/docs/
Author: markt
Date: Thu Dec 1 15:29:28 2016
New Revision: 1772229
URL: http://svn.apache.org/viewvc?rev=1772229&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=60431
Improve handling of varargs in UEL expressions.
Based on a patch by Ben.
Added:
tomcat/trunk/test/webapp/bug6nnnn/bug60431.jsp (with props)
Modified:
tomcat/trunk/java/org/apache/el/parser/AstFunction.java
tomcat/trunk/test/org/apache/el/TestELEvaluation.java
tomcat/trunk/test/org/apache/el/TestELInJsp.java
tomcat/trunk/test/org/apache/el/TesterFunctions.java
tomcat/trunk/test/webapp/WEB-INF/test.tld
tomcat/trunk/webapps/docs/changelog.xml
Modified: tomcat/trunk/java/org/apache/el/parser/AstFunction.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/AstFunction.java?rev=1772229&r1=1772228&r2=1772229&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/parser/AstFunction.java (original)
+++ tomcat/trunk/java/org/apache/el/parser/AstFunction.java Thu Dec 1 15:29:28 2016
@@ -163,13 +163,18 @@ public final class AstFunction extends S
Object result = null;
int inputParameterCount = parameters.jjtGetNumChildren();
int methodParameterCount = paramTypes.length;
- if (inputParameterCount > 0) {
+ if (inputParameterCount == 0 && methodParameterCount == 1 && m.isVarArgs()) {
+ params = new Object[] { null };
+ } else if (inputParameterCount > 0) {
params = new Object[methodParameterCount];
try {
for (int i = 0; i < methodParameterCount; i++) {
if (m.isVarArgs() && i == methodParameterCount - 1) {
if (inputParameterCount < methodParameterCount) {
- params[i] = null;
+ params[i] = new Object[] { null };
+ } else if (inputParameterCount == methodParameterCount &&
+ paramTypes[i].isArray()) {
+ params[i] = parameters.jjtGetChild(i).getValue(ctx);
} else {
Object[] varargs =
new Object[inputParameterCount - methodParameterCount + 1];
@@ -179,12 +184,11 @@ public final class AstFunction extends S
varargs[j-i] = coerceToType(ctx, varargs[j-i], target);
}
params[i] = varargs;
- params[i] = coerceToType(ctx, params[i], paramTypes[i]);
}
} else {
params[i] = parameters.jjtGetChild(i).getValue(ctx);
- params[i] = coerceToType(ctx, params[i], paramTypes[i]);
}
+ params[i] = coerceToType(ctx, params[i], paramTypes[i]);
}
} catch (ELException ele) {
throw new ELException(MessageFactory.get("error.function", this
Modified: tomcat/trunk/test/org/apache/el/TestELEvaluation.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/el/TestELEvaluation.java?rev=1772229&r1=1772228&r2=1772229&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/el/TestELEvaluation.java (original)
+++ tomcat/trunk/test/org/apache/el/TestELEvaluation.java Thu Dec 1 15:29:28 2016
@@ -231,6 +231,30 @@ public class TestELEvaluation {
Assert.assertEquals("$2", evaluateExpression("$#{1+1}"));
}
+ @Test
+ public void testBug60431a() {
+ Assert.assertEquals("OK", evaluateExpression("${fn:concat('O','K')}"));
+ }
+
+ @Test
+ public void testBug60431b() {
+ Assert.assertEquals("OK", evaluateExpression("${fn:concat(fn:toArray('O','K'))}"));
+ }
+
+ @Test
+ public void testBug60431c() {
+ Assert.assertEquals("", evaluateExpression("${fn:concat()}"));
+ }
+
+ @Test
+ public void testBug60431d() {
+ Assert.assertEquals("OK", evaluateExpression("${fn:concat2('OK')}"));
+ }
+
+ @Test
+ public void testBug60431e() {
+ Assert.assertEquals("RUOK", evaluateExpression("${fn:concat2('RU', fn:toArray('O','K'))}"));
+ }
// ************************************************************************
Modified: tomcat/trunk/test/org/apache/el/TestELInJsp.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/el/TestELInJsp.java?rev=1772229&r1=1772228&r2=1772229&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/el/TestELInJsp.java (original)
+++ tomcat/trunk/test/org/apache/el/TestELInJsp.java Thu Dec 1 15:29:28 2016
@@ -499,6 +499,17 @@ public class TestELInJsp extends TomcatB
}
+ @Test
+ public void testBug60431() throws Exception {
+ getTomcatInstanceTestWebapp(false, true);
+
+ ByteChunk res = getUrl("http://localhost:" + getPort() + "/test/bug6nnnn/bug60431.jsp");
+ String result = res.toString();
+ assertEcho(result, "01-OK");
+ assertEcho(result, "02-OK");
+ }
+
+
// Assertion for text contained with <p></p>, e.g. printed by tags:echo
private static void assertEcho(String result, String expected) {
Assert.assertTrue(result, result.indexOf("<p>" + expected + "</p>") > 0);
Modified: tomcat/trunk/test/org/apache/el/TesterFunctions.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/el/TesterFunctions.java?rev=1772229&r1=1772228&r2=1772229&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/el/TesterFunctions.java (original)
+++ tomcat/trunk/test/org/apache/el/TesterFunctions.java Thu Dec 1 15:29:28 2016
@@ -37,6 +37,18 @@ public class TesterFunctions {
return result.toString();
}
+ public static String concat2(String prefix, String... inputs) {
+ StringBuilder result = new StringBuilder(prefix);
+ for (String input : inputs) {
+ result.append(input);
+ }
+ return result.toString();
+ }
+
+ public static String[] toArray(String a, String b) {
+ return new String[] { a, b };
+ }
+
public static class Inner$Class {
@@ -58,6 +70,36 @@ public class TesterFunctions {
return m;
} catch (SecurityException e) {
// Ignore
+ } catch (NoSuchMethodException e) {
+ // Ignore
+ }
+ } else if ("concat".equals(localName)) {
+ Method m;
+ try {
+ m = TesterFunctions.class.getMethod("concat", String[].class);
+ return m;
+ } catch (SecurityException e) {
+ // Ignore
+ } catch (NoSuchMethodException e) {
+ // Ignore
+ }
+ } else if ("concat2".equals(localName)) {
+ Method m;
+ try {
+ m = TesterFunctions.class.getMethod("concat2", String.class, String[].class);
+ return m;
+ } catch (SecurityException e) {
+ // Ignore
+ } catch (NoSuchMethodException e) {
+ // Ignore
+ }
+ } else if ("toArray".equals(localName)) {
+ Method m;
+ try {
+ m = TesterFunctions.class.getMethod("toArray", String.class, String.class);
+ return m;
+ } catch (SecurityException e) {
+ // Ignore
} catch (NoSuchMethodException e) {
// Ignore
}
Modified: tomcat/trunk/test/webapp/WEB-INF/test.tld
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/WEB-INF/test.tld?rev=1772229&r1=1772228&r2=1772229&view=diff
==============================================================================
--- tomcat/trunk/test/webapp/WEB-INF/test.tld (original)
+++ tomcat/trunk/test/webapp/WEB-INF/test.tld Thu Dec 1 15:29:28 2016
@@ -40,4 +40,12 @@
</function-signature>
</function>
+ <function>
+ <name>toArray</name>
+ <function-class>org.apache.el.TesterFunctions</function-class>
+ <function-signature>
+ java.lang.String toArray(java.lang.String,java.lang.String)
+ </function-signature>
+ </function>
+
</taglib>
\ No newline at end of file
Added: tomcat/trunk/test/webapp/bug6nnnn/bug60431.jsp
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/bug6nnnn/bug60431.jsp?rev=1772229&view=auto
==============================================================================
--- tomcat/trunk/test/webapp/bug6nnnn/bug60431.jsp (added)
+++ tomcat/trunk/test/webapp/bug6nnnn/bug60431.jsp Thu Dec 1 15:29:28 2016
@@ -0,0 +1,25 @@
+<%--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+--%>
+<%@ taglib uri="http://tomcat.apache.org/testerFunctions" prefix="fn" %>
+<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
+<html>
+ <head><title>Bug 60431 test case</title></head>
+ <body>
+ <tags:echo echo="${'01-' += fn:concat('O', 'K')}"/>
+ <tags:echo echo="${'02-' += fn:concat(fn:toArray('O', 'K'))}"/>
+ </body>
+</html>
\ No newline at end of file
Propchange: tomcat/trunk/test/webapp/bug6nnnn/bug60431.jsp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1772229&r1=1772228&r2=1772229&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Dec 1 15:29:28 2016
@@ -192,6 +192,14 @@
</fix>
</changelog>
</subsection>
+ <subsection name="Jasper">
+ <changelog>
+ <fix>
+ <bug>60431</bug>: Improve handling of varargs in UEL expressions. Based
+ on a patch by Ben. (markt)
+ </fix>
+ </changelog>
+ </subsection>
<subsection name="Web applications">
<changelog>
<fix>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org