Deprecated Spring's own JSP expression evaluation
Since web applications declaring a Servlet 2.3 web.xml become really rare now, we're finally deprecating Spring's own ExpressionEvaluationUtils class. As a consequence, we're also setting "springJspExpressionSupport" to false by default, avoiding the potential double EL evaluation problem on pre-Servlet-3.0 containers. Issue: SPR-5308
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.web.util;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.PageContext;
|
||||
import javax.servlet.jsp.el.ELException;
|
||||
@@ -33,7 +34,7 @@ import org.springframework.mock.web.MockServletContext;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Aled Arendsen
|
||||
* @author Alef Arendsen
|
||||
* @author Juergen Hoeller
|
||||
* @since 16.09.2003
|
||||
*/
|
||||
@@ -43,9 +44,9 @@ public class ExpressionEvaluationUtilsTests {
|
||||
public void testIsSpringJspExpressionSupportActive() {
|
||||
MockServletContext sc = new MockServletContext();
|
||||
PageContext pc = new MockPageContext(sc);
|
||||
assertTrue(ExpressionEvaluationUtils.isSpringJspExpressionSupportActive(pc));
|
||||
sc.addInitParameter("springJspExpressionSupport", "false");
|
||||
assertFalse(ExpressionEvaluationUtils.isSpringJspExpressionSupportActive(pc));
|
||||
sc.addInitParameter("springJspExpressionSupport", "true");
|
||||
assertTrue(ExpressionEvaluationUtils.isSpringJspExpressionSupportActive(pc));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,7 +83,9 @@ public class ExpressionEvaluationUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testEvaluate() throws Exception {
|
||||
PageContext ctx = new MockPageContext();
|
||||
MockServletContext sc = new MockServletContext();
|
||||
sc.addInitParameter("springJspExpressionSupport", "true");
|
||||
MockPageContext ctx = new MockPageContext(sc);
|
||||
ctx.setAttribute("bla", "blie");
|
||||
|
||||
assertEquals("blie", ExpressionEvaluationUtils.evaluate("test", "${bla}", String.class, ctx));
|
||||
@@ -99,7 +102,9 @@ public class ExpressionEvaluationUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testEvaluateWithConcatenation() throws Exception {
|
||||
PageContext ctx = new MockPageContext();
|
||||
MockServletContext sc = new MockServletContext();
|
||||
sc.addInitParameter("springJspExpressionSupport", "true");
|
||||
MockPageContext ctx = new MockPageContext(sc);
|
||||
ctx.setAttribute("bla", "blie");
|
||||
|
||||
String expr = "text${bla}text${bla}text";
|
||||
@@ -139,7 +144,9 @@ public class ExpressionEvaluationUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testEvaluateString() throws Exception {
|
||||
PageContext ctx = new MockPageContext();
|
||||
MockServletContext sc = new MockServletContext();
|
||||
sc.addInitParameter("springJspExpressionSupport", "true");
|
||||
MockPageContext ctx = new MockPageContext(sc);
|
||||
ctx.setAttribute("bla", "blie");
|
||||
|
||||
assertEquals("blie", ExpressionEvaluationUtils.evaluateString("test", "${bla}", ctx));
|
||||
@@ -148,7 +155,9 @@ public class ExpressionEvaluationUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testEvaluateStringWithConcatenation() throws Exception {
|
||||
PageContext ctx = new MockPageContext();
|
||||
MockServletContext sc = new MockServletContext();
|
||||
sc.addInitParameter("springJspExpressionSupport", "true");
|
||||
MockPageContext ctx = new MockPageContext(sc);
|
||||
ctx.setAttribute("bla", "blie");
|
||||
|
||||
String expr = "text${bla}text${bla}text";
|
||||
@@ -180,7 +189,9 @@ public class ExpressionEvaluationUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testEvaluateInteger() throws Exception {
|
||||
PageContext ctx = new MockPageContext();
|
||||
MockServletContext sc = new MockServletContext();
|
||||
sc.addInitParameter("springJspExpressionSupport", "true");
|
||||
MockPageContext ctx = new MockPageContext(sc);
|
||||
ctx.setAttribute("bla", new Integer(1));
|
||||
|
||||
assertEquals(1, ExpressionEvaluationUtils.evaluateInteger("test", "${bla}", ctx));
|
||||
@@ -189,7 +200,9 @@ public class ExpressionEvaluationUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testEvaluateBoolean() throws Exception {
|
||||
PageContext ctx = new MockPageContext();
|
||||
MockServletContext sc = new MockServletContext();
|
||||
sc.addInitParameter("springJspExpressionSupport", "true");
|
||||
MockPageContext ctx = new MockPageContext(sc);
|
||||
ctx.setAttribute("bla", new Boolean(true));
|
||||
|
||||
assertTrue(ExpressionEvaluationUtils.evaluateBoolean("test", "${bla}", ctx));
|
||||
@@ -198,7 +211,9 @@ public class ExpressionEvaluationUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testRepeatedEvaluate() throws Exception {
|
||||
PageContext ctx = new CountingMockPageContext();
|
||||
MockServletContext sc = new MockServletContext();
|
||||
sc.addInitParameter("springJspExpressionSupport", "true");
|
||||
PageContext ctx = new CountingMockPageContext(sc);
|
||||
CountingMockExpressionEvaluator eval = (CountingMockExpressionEvaluator) ctx.getExpressionEvaluator();
|
||||
ctx.setAttribute("bla", "blie");
|
||||
ctx.setAttribute("blo", "blue");
|
||||
@@ -218,7 +233,9 @@ public class ExpressionEvaluationUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testEvaluateWithComplexConcatenation() throws Exception {
|
||||
PageContext ctx = new CountingMockPageContext();
|
||||
MockServletContext sc = new MockServletContext();
|
||||
sc.addInitParameter("springJspExpressionSupport", "true");
|
||||
PageContext ctx = new CountingMockPageContext(sc);
|
||||
CountingMockExpressionEvaluator eval = (CountingMockExpressionEvaluator) ctx.getExpressionEvaluator();
|
||||
ctx.setAttribute("bla", "blie");
|
||||
ctx.setAttribute("blo", "blue");
|
||||
@@ -247,6 +264,10 @@ public class ExpressionEvaluationUtilsTests {
|
||||
|
||||
private static class CountingMockPageContext extends MockPageContext {
|
||||
|
||||
public CountingMockPageContext(ServletContext servletContext) {
|
||||
super(servletContext);
|
||||
}
|
||||
|
||||
private ExpressionEvaluator eval = new CountingMockExpressionEvaluator(this);
|
||||
|
||||
public ExpressionEvaluator getExpressionEvaluator() {
|
||||
|
||||
Reference in New Issue
Block a user