WW-5424 Fixes ClassCastException when using short var name in s:set tag

This commit is contained in:
Lukasz Lenart
2024-06-02 13:53:37 +02:00
parent 9682b3b429
commit 4a8ff99b1c
2 changed files with 55 additions and 15 deletions
@@ -104,17 +104,17 @@ public class Set extends ContextBean {
body="";
if (DispatcherConstants.APPLICATION.equalsIgnoreCase(scope)) {
stack.setValue("#application['" + getVar() + "']", o);
stack.setValue(String.format("#application[\"%s\"]", getVar()), o);
} else if (DispatcherConstants.SESSION.equalsIgnoreCase(scope)) {
stack.setValue("#session['" + getVar() + "']", o);
stack.setValue(String.format("#session[\"%s\"]", getVar()), o);
} else if (DispatcherConstants.REQUEST.equalsIgnoreCase(scope)) {
stack.setValue("#request['" + getVar() + "']", o);
stack.setValue(String.format("#request[\"%s\"]", getVar()), o);
} else if (DispatcherConstants.PAGE.equalsIgnoreCase(scope)) {
stack.setValue("#attr['" + getVar() + "']", o, false);
stack.setValue(String.format("#attr[\"%s\"]", getVar()), o, false);
} else {
// Default scope is action. Note: The action scope handling also adds the var to the page scope.
stack.getContext().put(getVar(), o);
stack.setValue("#attr['" + getVar() + "']", o, false);
putInContext(o);
stack.setValue(String.format("#attr[\"%s\"]", getVar()), o, false);
}
return super.end(writer, body);
@@ -22,14 +22,10 @@ import com.mockobjects.servlet.MockJspWriter;
import java.io.IOException;
import javax.servlet.jsp.JspException;
/**
*/
public class SetTagTest extends AbstractUITagTest {
Chewbacca chewie;
SetTag tag;
private Chewbacca chewie;
private SetTag tag;
public void testApplicationScope() throws JspException {
tag.setName("foo");
@@ -397,6 +393,50 @@ public class SetTagTest extends AbstractUITagTest {
strutsBodyTagsAreReflectionEqual(tag, freshTag));
}
public void testShortVarNameInPageScope() throws JspException {
tag.setName("f");
tag.setValue("name");
tag.setScope("page");
tag.doStartTag();
tag.doEndTag();
assertEquals("chewie", pageContext.getAttribute("f"));
}
public void testShortVarNameInRequestScope() throws JspException {
tag.setName("f");
tag.setValue("name");
tag.setScope("request");
tag.doStartTag();
tag.doEndTag();
assertEquals("chewie", request.getAttribute("f"));
}
public void testShortVarNameInSessionScope() throws JspException {
tag.setName("f");
tag.setValue("name");
tag.setScope("session");
tag.doStartTag();
tag.doEndTag();
assertEquals("chewie", session.get("f"));
}
public void testShortVarNameInApplicationScope() throws JspException {
tag.setName("f");
tag.setValue("name");
tag.setScope("application");
tag.doStartTag();
tag.doEndTag();
assertEquals("chewie", servletContext.getAttribute("f"));
}
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -408,9 +448,9 @@ public class SetTagTest extends AbstractUITagTest {
}
public class Chewbacca {
String name;
boolean furry;
public static class Chewbacca {
private String name;
private boolean furry;
public Chewbacca(String name, boolean furry) {
this.name = name;