Author: markt Date: Thu Aug 6 14:02:43 2015 New Revision: 1694501 URL: http://svn.apache.org/r1694501 Log: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=58178 EL in a tag file should use the Tag file's page context rather than that of the containing page.
Added: tomcat/trunk/test/org/apache/jasper/runtime/TestJspContextWrapper.java (with props) tomcat/trunk/test/webapp/WEB-INF/tags/bug58178.tag tomcat/trunk/test/webapp/bug5nnnn/bug58178.jsp (with props) Modified: tomcat/trunk/java/org/apache/jasper/el/ELContextImpl.java tomcat/trunk/java/org/apache/jasper/runtime/JspContextWrapper.java tomcat/trunk/java/org/apache/jasper/runtime/PageContextImpl.java Modified: tomcat/trunk/java/org/apache/jasper/el/ELContextImpl.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/el/ELContextImpl.java?rev=1694501&r1=1694500&r2=1694501&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/el/ELContextImpl.java (original) +++ tomcat/trunk/java/org/apache/jasper/el/ELContextImpl.java Thu Aug 6 14:02:43 2015 @@ -42,7 +42,7 @@ import org.apache.jasper.Constants; * * @author Jacob Hookom */ -public final class ELContextImpl extends ELContext { +public class ELContextImpl extends ELContext { private static final FunctionMapper NullFunctionMapper = new FunctionMapper() { @Override Modified: tomcat/trunk/java/org/apache/jasper/runtime/JspContextWrapper.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/runtime/JspContextWrapper.java?rev=1694501&r1=1694500&r2=1694501&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/runtime/JspContextWrapper.java (original) +++ tomcat/trunk/java/org/apache/jasper/runtime/JspContextWrapper.java Thu Aug 6 14:02:43 2015 @@ -23,9 +23,16 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; +import java.util.List; +import java.util.Locale; import java.util.Map; import javax.el.ELContext; +import javax.el.ELResolver; +import javax.el.EvaluationListener; +import javax.el.FunctionMapper; +import javax.el.ImportHandler; +import javax.el.VariableMapper; import javax.servlet.Servlet; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; @@ -492,26 +499,135 @@ public class JspContextWrapper extends P return alias; } - //private ELContextImpl elContext; - @Override public ELContext getELContext() { - // instead decorate!!! - if (elContext == null) { - elContext = rootJspCtxt.getELContext(); + elContext = new ELContextWrapper(rootJspCtxt.getELContext(), this); } return elContext; + } + + + static class ELContextWrapper extends ELContext { + + private final ELContext wrapped; + private final PageContext pageContext; + + private ELContextWrapper(ELContext wrapped, PageContext pageContext) { + this.wrapped = wrapped; + this.pageContext = pageContext; + } + + ELContext getWrappedELContext() { + return wrapped; + } + + @Override + public void setPropertyResolved(boolean resolved) { + wrapped.setPropertyResolved(resolved); + } + + @Override + public void setPropertyResolved(Object base, Object property) { + wrapped.setPropertyResolved(base, property); + } + + @Override + public boolean isPropertyResolved() { + return wrapped.isPropertyResolved(); + } + + @Override + public void putContext(@SuppressWarnings("rawtypes") Class key, Object contextObject) { + wrapped.putContext(key, contextObject); + } + + @Override + public Object getContext(@SuppressWarnings("rawtypes") Class key) { + if (key == JspContext.class) { + return pageContext; + } + return wrapped.getContext(key); + } + + @Override + public ImportHandler getImportHandler() { + return wrapped.getImportHandler(); + } + + @Override + public Locale getLocale() { + return wrapped.getLocale(); + } + + @Override + public void setLocale(Locale locale) { + wrapped.setLocale(locale); + } + + @Override + public void addEvaluationListener(EvaluationListener listener) { + wrapped.addEvaluationListener(listener); + } + + @Override + public List<EvaluationListener> getEvaluationListeners() { + return wrapped.getEvaluationListeners(); + } + + @Override + public void notifyBeforeEvaluation(String expression) { + wrapped.notifyBeforeEvaluation(expression); + } + + @Override + public void notifyAfterEvaluation(String expression) { + wrapped.notifyAfterEvaluation(expression); + } + + @Override + public void notifyPropertyResolved(Object base, Object property) { + wrapped.notifyPropertyResolved(base, property); + } + + @Override + public boolean isLambdaArgument(String name) { + return wrapped.isLambdaArgument(name); + } + + @Override + public Object getLambdaArgument(String name) { + return wrapped.getLambdaArgument(name); + } + + @Override + public void enterLambdaScope(Map<String, Object> arguments) { + wrapped.enterLambdaScope(arguments); + } + + @Override + public void exitLambdaScope() { + wrapped.exitLambdaScope(); + } + + @Override + public Object convertToType(Object obj, Class<?> type) { + return wrapped.convertToType(obj, type); + } + + @Override + public ELResolver getELResolver() { + return wrapped.getELResolver(); + } + + @Override + public FunctionMapper getFunctionMapper() { + return wrapped.getFunctionMapper(); + } - /* - if (this.elContext != null) { - JspFactory jspFact = JspFactory.getDefaultFactory(); - ServletContext servletContext = this.getServletContext(); - JspApplicationContextImpl jspCtx = (JspApplicationContextImpl) jspFact - .getJspApplicationContext(servletContext); - this.elContext = jspCtx.createELContext(this); + @Override + public VariableMapper getVariableMapper() { + return wrapped.getVariableMapper(); } - return this.elContext; - */ } } Modified: tomcat/trunk/java/org/apache/jasper/runtime/PageContextImpl.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/runtime/PageContextImpl.java?rev=1694501&r1=1694500&r2=1694501&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/runtime/PageContextImpl.java (original) +++ tomcat/trunk/java/org/apache/jasper/runtime/PageContextImpl.java Thu Aug 6 14:02:43 2015 @@ -52,6 +52,7 @@ import javax.servlet.jsp.tagext.BodyCont import org.apache.jasper.Constants; import org.apache.jasper.compiler.Localizer; import org.apache.jasper.el.ELContextImpl; +import org.apache.jasper.runtime.JspContextWrapper.ELContextWrapper; import org.apache.jasper.security.SecurityUtil; /** @@ -930,8 +931,14 @@ public class PageContextImpl extends Pag final ProtectedFunctionMapper functionMap) throws ELException { final ExpressionFactory exprFactory = jspf.getJspApplicationContext(pageContext.getServletContext()).getExpressionFactory(); - ELContextImpl ctx = (ELContextImpl) pageContext.getELContext(); - ctx.setFunctionMapper(functionMap); + ELContext ctx = pageContext.getELContext(); + ELContextImpl ctxImpl; + if (ctx instanceof ELContextWrapper) { + ctxImpl = (ELContextImpl) ((ELContextWrapper) ctx).getWrappedELContext(); + } else { + ctxImpl = (ELContextImpl) ctx; + } + ctxImpl.setFunctionMapper(functionMap); ValueExpression ve = exprFactory.createValueExpression(ctx, expression, expectedType); return ve.getValue(ctx); } Added: tomcat/trunk/test/org/apache/jasper/runtime/TestJspContextWrapper.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/runtime/TestJspContextWrapper.java?rev=1694501&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/jasper/runtime/TestJspContextWrapper.java (added) +++ tomcat/trunk/test/org/apache/jasper/runtime/TestJspContextWrapper.java Thu Aug 6 14:02:43 2015 @@ -0,0 +1,30 @@ +package org.apache.jasper.runtime; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.catalina.startup.TomcatBaseTest; +import org.apache.tomcat.util.buf.ByteChunk; +import org.junit.Assert; +import org.junit.Test; + +public class TestJspContextWrapper extends TomcatBaseTest { + + @Test + public void testELTagFilePageContext() throws Exception { + getTomcatInstanceTestWebapp(true, true); + + ByteChunk out = new ByteChunk(); + + int rc = getUrl("http://localhost:" + getPort() + "/test/bug5nnnn/bug58178.jsp", out, null); + + Assert.assertEquals(HttpServletResponse.SC_OK, rc); + + String result = out.toString(); + + Assert.assertTrue(result, result.contains("PASS")); + } + + public void testELTagFileImports() { + + } +} Propchange: tomcat/trunk/test/org/apache/jasper/runtime/TestJspContextWrapper.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/test/webapp/WEB-INF/tags/bug58178.tag URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/WEB-INF/tags/bug58178.tag?rev=1694501&view=auto ============================================================================== --- tomcat/trunk/test/webapp/WEB-INF/tags/bug58178.tag (added) +++ tomcat/trunk/test/webapp/WEB-INF/tags/bug58178.tag Thu Aug 6 14:02:43 2015 @@ -0,0 +1,16 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + +<c:catch var="error"> + <jsp:doBody/> +</c:catch> + +<c:if test="${error != null}"> + <p>PASS<br/> + Error detected<br/> + The exception is : ${error} <br /> + The message is: ${error.message}</p> +</c:if> +<c:if test="${error == null}"> + <p>FAIL<br/> + Error not detected</p> +</c:if> \ No newline at end of file Added: tomcat/trunk/test/webapp/bug5nnnn/bug58178.jsp URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/bug5nnnn/bug58178.jsp?rev=1694501&view=auto ============================================================================== --- tomcat/trunk/test/webapp/bug5nnnn/bug58178.jsp (added) +++ tomcat/trunk/test/webapp/bug5nnnn/bug58178.jsp Thu Aug 6 14:02:43 2015 @@ -0,0 +1,14 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<html> +<head> +<title>Catch Tag Example</title> +</head> +<body> + +<tags:bug58178> + <fmt:parseNumber var="parsedNum" value="aaa" /> +</tags:bug58178> +Parsed value: <c:out value="${parsedNum}"/> +</html> \ No newline at end of file Propchange: tomcat/trunk/test/webapp/bug5nnnn/bug58178.jsp ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org