Skip to content

Commit 6df90bf

Browse files
committed
WW-5086 Fixes s:set tag with empty body
1 parent 8896015 commit 6df90bf

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

core/src/main/java/org/apache/struts2/components/Set.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
* complex expression and then simply reference that variable each time rather than the complex expression. This is
3232
* useful in both cases: when the complex expression takes time (performance improvement) or is hard to read (code
3333
* readability improvement).</p>
34-
* <p>If the tag is used with body content, the evaluation of the value parameter is omitted. Instead, the String to
35-
* which the body evaluates is set as value for the scoped variable.</p>
34+
* <p>If the value parameter is omitted, the String to which the body evaluates is set as value for the scoped variable.</p>
3635
*
3736
* <p>The scopes available are as follows:</p>
3837
* <ul>
@@ -94,11 +93,7 @@ public boolean end(Writer writer, String body) {
9493

9594
Object o;
9695
if (value == null) {
97-
if (body != null && !body.equals("")) {
98-
o = body;
99-
} else {
100-
o = findValue("top");
101-
}
96+
o = body;
10297
} else {
10398
o = findValue(value);
10499
}

core/src/test/java/org/apache/struts2/views/jsp/SetTagTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ public void testSetTrimBody() throws JspException, IOException {
121121
assertEquals(beginEndSpaceString, context.get("foo"));
122122
}
123123

124+
public void testEmptyBody() throws JspException {
125+
StrutsMockBodyContent mockBodyContent;
126+
String variableName = "foo";
127+
tag.setName(variableName);
128+
tag.setValue(null);
129+
mockBodyContent = new StrutsMockBodyContent(new MockJspWriter());
130+
String emptyBody = "";
131+
mockBodyContent.setString(emptyBody);
132+
tag.setBodyContent(mockBodyContent);
133+
tag.doStartTag();
134+
tag.doEndTag();
135+
assertEquals(emptyBody, context.get(variableName));
136+
}
137+
124138
protected void setUp() throws Exception {
125139
super.setUp();
126140

0 commit comments

Comments
 (0)