Repository: struts Updated Branches: refs/heads/master ab6750211 -> 366366cdd
WW-4711 Disables evaluating ValueStack by default Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/996475d7 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/996475d7 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/996475d7 Branch: refs/heads/master Commit: 996475d755820914ea4695729ec46159f12625e0 Parents: ab67502 Author: Lukasz Lenart <lukaszlen...@apache.org> Authored: Fri Nov 11 11:52:40 2016 +0100 Committer: Lukasz Lenart <lukaszlen...@apache.org> Committed: Fri Nov 11 11:52:40 2016 +0100 ---------------------------------------------------------------------- .../java/org/apache/struts2/components/Text.java | 18 ++++++++++++------ .../org/apache/struts2/views/jsp/TextTagTest.java | 6 +++--- 2 files changed, 15 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/struts/blob/996475d7/core/src/main/java/org/apache/struts2/components/Text.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/struts2/components/Text.java b/core/src/main/java/org/apache/struts2/components/Text.java index 69c0344..3f7c15e 100644 --- a/core/src/main/java/org/apache/struts2/components/Text.java +++ b/core/src/main/java/org/apache/struts2/components/Text.java @@ -51,7 +51,7 @@ import java.util.List; * * <p> * If the named message is not found in a property file, then the body of the - * tag will be used as default message. If no body is used, then the stack will + * tag will be used as default message. If no body is used, then the stack can * be searched, and if a value is returned, it will written to the output. * If no value is found on the stack, the key of the message will be written out. * </p> @@ -115,9 +115,10 @@ import java.util.List; tldTagClass="org.apache.struts2.views.jsp.TextTag", description="Render a I18n text message") public class Text extends ContextBean implements Param.UnnamedParametric { + private static final Logger LOG = LogManager.getLogger(Text.class); - protected List values = Collections.EMPTY_LIST; + protected List<Object> values = Collections.emptyList(); protected String actualName; protected String name; protected String searchStack; @@ -131,7 +132,7 @@ public class Text extends ContextBean implements Param.UnnamedParametric { this.name = name; } - @StrutsTagAttribute(description="Search the stack if property is not found on resources", type = "Boolean", defaultValue = "true") + @StrutsTagAttribute(description="Search the stack if property is not found on resources", type = "Boolean", defaultValue = "false") public void setSearchValueStack(String searchStack) { this.searchStack = searchStack; } @@ -152,8 +153,13 @@ public class Text extends ContextBean implements Param.UnnamedParametric { defaultMessage = actualName; } - Boolean doSearchStack = searchStack != null ? (Boolean) findValue(searchStack, Boolean.class) : true; - String msg = TextProviderHelper.getText(actualName, defaultMessage, values, getStack(), doSearchStack == null || doSearchStack); + Boolean doSearchStack = false; + if (searchStack != null) { + Object value = findValue(searchStack, Boolean.class); + doSearchStack = value != null ? (Boolean) value : false; + } + + String msg = TextProviderHelper.getText(actualName, defaultMessage, values, getStack(), doSearchStack); if (msg != null) { try { @@ -176,7 +182,7 @@ public class Text extends ContextBean implements Param.UnnamedParametric { public void addParameter(Object value) { if (values.isEmpty()) { - values = new ArrayList(4); + values = new ArrayList<>(4); } values.add(value); http://git-wip-us.apache.org/repos/asf/struts/blob/996475d7/core/src/test/java/org/apache/struts2/views/jsp/TextTagTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/struts2/views/jsp/TextTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/TextTagTest.java index 651fa3d..729ecaf 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/TextTagTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/TextTagTest.java @@ -218,10 +218,11 @@ public class TextTagTest extends AbstractTagTest { assertEquals(value_int, writer.toString()); } - public void testTextTagSearchesStackByDefault() throws JspException { + public void testTextTagCanSearchStackToFindValue() throws JspException { String key = "result"; tag.setName(key); + tag.setSearchValueStack("true"); final StringBuffer buffer = writer.getBuffer(); buffer.delete(0, buffer.length()); ValueStack newStack = container.getInstance(ValueStackFactory.class).createValueStack(); @@ -238,11 +239,10 @@ public class TextTagTest extends AbstractTagTest { assertEquals("bar", writer.toString()); } - public void testTextTagDoNotSearchStack() throws JspException { + public void testTextTagDoNotSearchStackByDefault() throws JspException { String key = "result"; tag.setName(key); - tag.setSearchValueStack("false"); final StringBuffer buffer = writer.getBuffer(); buffer.delete(0, buffer.length()); ValueStack newStack = container.getInstance(ValueStackFactory.class).createValueStack();