From 677cf5c8ce51d78fb363541b9ba8978264330f75 Mon Sep 17 00:00:00 2001 From: markt Date: Wed, 6 Jan 2010 18:51:24 +0000 Subject: [PATCH] Add a test case for bug 48112 (note this passes - need to check when used in a JSP) git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@896620 13f79535-47bb-0310-9956-ffa450edef68 --- test/org/apache/el/TestELEvaluation.java | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/org/apache/el/TestELEvaluation.java b/test/org/apache/el/TestELEvaluation.java index 08f6d9171..0c21ff43d 100644 --- a/test/org/apache/el/TestELEvaluation.java +++ b/test/org/apache/el/TestELEvaluation.java @@ -18,9 +18,11 @@ package org.apache.el; import java.io.File; +import java.lang.reflect.Method; import java.util.Date; import javax.el.ValueExpression; +import javax.el.FunctionMapper; import org.apache.el.ExpressionFactoryImpl; import org.apache.el.lang.ELSupport; @@ -90,6 +92,11 @@ public class TestELEvaluation extends TestCase { assertEquals("\"\\", evaluateExpression("${\"\\\"\\\\\"}")); } + public void testParserFunction() { + // bug 48112 + assertEquals("{world}", evaluateExpression("${fn:trim('{world}')}")); + } + private void compareBoth(String msg, int expected, Object o1, Object o2){ int i1 = ELSupport.compare(o1, o2); int i2 = ELSupport.compare(o2, o1); @@ -116,9 +123,33 @@ public class TestELEvaluation extends TestCase { private String evaluateExpression(String expression) { ELContextImpl ctx = new ELContextImpl(); + ctx.setFunctionMapper(new FMapper()); ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl(); ValueExpression ve = exprFactory.createValueExpression(ctx, expression, String.class); return (String) ve.getValue(ctx); } + + public static class FMapper extends FunctionMapper { + + @Override + public Method resolveFunction(String prefix, String localName) { + if ("trim".equals(localName)) { + Method m; + try { + m = this.getClass().getMethod("trim", String.class); + return m; + } catch (SecurityException e) { + // Ignore + } catch (NoSuchMethodException e) { + // Ignore + } + } + return null; + } + + public static String trim(String input) { + return input.trim(); + } + } } -- 2.11.0