Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix implicit variable resolution in JSP EvalTag #33945

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private Object resolveImplicitVariable(String name) throws AccessException {
return null;
}
try {
return this.elContext.getELResolver().getValue(this.elContext, name, null);
return this.elContext.getELResolver().getValue(this.elContext, null, name);
}
catch (Exception ex) {
throw new AccessException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
import java.util.Locale;
import java.util.Map;

import jakarta.el.ELContext;
import jakarta.el.ELResolver;
import jakarta.servlet.jsp.tagext.Tag;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.mockito.ArgumentMatchers;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.env.MapPropertySource;
Expand All @@ -37,6 +40,12 @@
import org.springframework.web.testfixture.servlet.MockPageContext;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

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

context = createPageContext();
context = spy(createPageContext());
final ELContext elContext = mock(ELContext.class);
final ELResolver elResolver = when(mock(ELResolver.class).getValue(same(elContext), isNull(), eq("pageContext")))
.thenReturn(context)
.getMock();
when(elContext.getELResolver()).thenReturn(elResolver);
when(context.getELContext()).thenReturn(elContext);
FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean();
factory.afterPropertiesSet();
context.getRequest().setAttribute("org.springframework.core.convert.ConversionService", factory.getObject());
Expand Down Expand Up @@ -181,7 +196,15 @@ void mapAccess() throws Exception {
assertThat(((MockHttpServletResponse) context.getResponse()).getContentAsString()).isEqualTo("value");
}


@Test
void resolveImplicitVariable() throws Exception {
tag.setExpression("pageContext.getClass().getSimpleName()");
int action = tag.doStartTag();
assertThat(action).isEqualTo(Tag.EVAL_BODY_INCLUDE);
action = tag.doEndTag();
assertThat(action).isEqualTo(Tag.EVAL_PAGE);
assertThat(((MockHttpServletResponse) context.getResponse()).getContentAsString()).isEqualTo("MockPageContext");
}

public static class Bean {

Expand Down