Skip to content

Commit 71f872e

Browse files
micopiirasbrannen
authored andcommitted
Fix implicit variable resolution in JSP EvalTag
Prior to this commit, the order of parameters passed to ELResolver#getValue was incorrect. The `name` should correspond to the `property` parameter of the `getValue` method instead the `base` parameter. See gh-32383 See gh-33942 Closes gh-33945
1 parent 54a90b2 commit 71f872e

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EvalTag.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ private Object resolveImplicitVariable(String name) throws AccessException {
259259
return null;
260260
}
261261
try {
262-
return this.elContext.getELResolver().getValue(this.elContext, name, null);
262+
return this.elContext.getELResolver().getValue(this.elContext, null, name);
263263
}
264264
catch (Exception ex) {
265265
throw new AccessException(

spring-webmvc/src/test/java/org/springframework/web/servlet/tags/EvalTagTests.java

+25-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
import java.util.Locale;
2222
import java.util.Map;
2323

24+
import jakarta.el.ELContext;
25+
import jakarta.el.ELResolver;
2426
import jakarta.servlet.jsp.tagext.Tag;
2527
import org.junit.jupiter.api.AfterEach;
2628
import org.junit.jupiter.api.BeforeEach;
2729
import org.junit.jupiter.api.Test;
2830

31+
import org.mockito.ArgumentMatchers;
2932
import org.springframework.context.i18n.LocaleContextHolder;
3033
import org.springframework.context.support.GenericApplicationContext;
3134
import org.springframework.core.env.MapPropertySource;
@@ -37,6 +40,12 @@
3740
import org.springframework.web.testfixture.servlet.MockPageContext;
3841

3942
import static org.assertj.core.api.Assertions.assertThat;
43+
import static org.mockito.ArgumentMatchers.eq;
44+
import static org.mockito.ArgumentMatchers.isNull;
45+
import static org.mockito.ArgumentMatchers.same;
46+
import static org.mockito.Mockito.mock;
47+
import static org.mockito.Mockito.spy;
48+
import static org.mockito.Mockito.when;
4049

4150
/**
4251
* @author Keith Donald
@@ -52,7 +61,13 @@ class EvalTagTests extends AbstractTagTests {
5261
void setup() {
5362
LocaleContextHolder.setDefaultLocale(Locale.UK);
5463

55-
context = createPageContext();
64+
context = spy(createPageContext());
65+
final ELContext elContext = mock(ELContext.class);
66+
final ELResolver elResolver = when(mock(ELResolver.class).getValue(same(elContext), isNull(), eq("pageContext")))
67+
.thenReturn(context)
68+
.getMock();
69+
when(elContext.getELResolver()).thenReturn(elResolver);
70+
when(context.getELContext()).thenReturn(elContext);
5671
FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean();
5772
factory.afterPropertiesSet();
5873
context.getRequest().setAttribute("org.springframework.core.convert.ConversionService", factory.getObject());
@@ -181,7 +196,15 @@ void mapAccess() throws Exception {
181196
assertThat(((MockHttpServletResponse) context.getResponse()).getContentAsString()).isEqualTo("value");
182197
}
183198

184-
199+
@Test
200+
void resolveImplicitVariable() throws Exception {
201+
tag.setExpression("pageContext.getClass().getSimpleName()");
202+
int action = tag.doStartTag();
203+
assertThat(action).isEqualTo(Tag.EVAL_BODY_INCLUDE);
204+
action = tag.doEndTag();
205+
assertThat(action).isEqualTo(Tag.EVAL_PAGE);
206+
assertThat(((MockHttpServletResponse) context.getResponse()).getContentAsString()).isEqualTo("MockPageContext");
207+
}
185208

186209
public static class Bean {
187210

0 commit comments

Comments
 (0)