mirror of
https://github.com/apache/struts.git
synced 2026-08-06 07:06:58 +00:00
WW-5022 Pass escapeHtmlBody flag to JavaTemplates tags
This commit is contained in:
@@ -112,6 +112,8 @@ public class Anchor extends ClosingUIBean {
|
||||
addParameter("href", ensureAttributeSafelyNotEscaped(builtHref));
|
||||
}
|
||||
}
|
||||
|
||||
addParameter("escapeHtmlBody", escapeHtmlBody);
|
||||
}
|
||||
|
||||
@Inject(StrutsConstants.STRUTS_URL_INCLUDEPARAMS)
|
||||
@@ -264,7 +266,7 @@ public class Anchor extends ClosingUIBean {
|
||||
urlProvider.setForceAddSchemeHostAndPort(forceAddSchemeHostAndPort);
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description = "Specifies whether to HTML-escape the tag body or not", type = "Boolean", defaultValue = "true")
|
||||
@StrutsTagAttribute(description = "Specifies whether to HTML-escape the tag body or not", type = "Boolean", defaultValue = "false")
|
||||
public void setEscapeHtmlBody(boolean escapeHtmlBody) {
|
||||
this.escapeHtmlBody = escapeHtmlBody;
|
||||
}
|
||||
|
||||
@@ -85,8 +85,11 @@ public class Submit extends FormButton {
|
||||
public void evaluateExtraParams() {
|
||||
super.evaluateExtraParams();
|
||||
|
||||
if (src != null)
|
||||
if (src != null) {
|
||||
addParameter("src", findString(src));
|
||||
}
|
||||
|
||||
addParameter("escapeHtmlBody", escapeHtmlBody);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,7 +106,7 @@ public class Submit extends FormButton {
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description = "Specifies whether to HTML-escape the tag body or not", type = "Boolean", defaultValue = "true")
|
||||
@StrutsTagAttribute(description = "Specifies whether to HTML-escape the tag body or not", type = "Boolean", defaultValue = "false")
|
||||
public void setEscapeHtmlBody(boolean escapeHtmlBody) {
|
||||
this.escapeHtmlBody = escapeHtmlBody;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
<tr>
|
||||
<td align="left" valign="top">escapeHtmlBody</td>
|
||||
<td align="left" valign="top">false</td>
|
||||
<td align="left" valign="top">true</td>
|
||||
<td align="left" valign="top">false</td>
|
||||
<td align="left" valign="top">false</td>
|
||||
<td align="left" valign="top">Boolean</td>
|
||||
<td align="left" valign="top">Specifies whether to HTML-escape the tag body or not</td>
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
<tr>
|
||||
<td align="left" valign="top">escapeHtmlBody</td>
|
||||
<td align="left" valign="top">false</td>
|
||||
<td align="left" valign="top">true</td>
|
||||
<td align="left" valign="top">false</td>
|
||||
<td align="left" valign="top">false</td>
|
||||
<td align="left" valign="top">Boolean</td>
|
||||
<td align="left" valign="top">Specifies whether to HTML-escape the tag body or not</td>
|
||||
|
||||
+7
-6
@@ -22,14 +22,15 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
/**
|
||||
* Default implementation of TagHandlerFactory
|
||||
* Default implementation of TagHandlerFactory
|
||||
*/
|
||||
public class DefaultTagHandlerFactory implements TagHandlerFactory {
|
||||
private static final Logger LOG = LogManager.getLogger(DefaultTagHandlerFactory.class);
|
||||
|
||||
private Class tagHandlerClass;
|
||||
|
||||
public DefaultTagHandlerFactory(Class tagHandlerClass) {
|
||||
private static final Logger LOG = LogManager.getLogger(DefaultTagHandlerFactory.class);
|
||||
|
||||
private final Class<?> tagHandlerClass;
|
||||
|
||||
public DefaultTagHandlerFactory(Class<?> tagHandlerClass) {
|
||||
this.tagHandlerClass = tagHandlerClass;
|
||||
}
|
||||
|
||||
@@ -41,7 +42,7 @@ public class DefaultTagHandlerFactory implements TagHandlerFactory {
|
||||
} catch (Exception e) {
|
||||
LOG.error("Failed to instantiate tag handler class [{}]", tagHandlerClass.getName(), e);
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -45,8 +45,10 @@ public class AnchorHandler extends AbstractTagHandler implements TagGenerator {
|
||||
.addIfExists("tabindex", params.get("tabindex"));
|
||||
start("a", attrs);
|
||||
String body = (String) params.get("body");
|
||||
if (StringUtils.isNotEmpty(body))
|
||||
characters(body, false);
|
||||
Boolean escapeHtmlBody = (Boolean) params.get("escapeHtmlBody");
|
||||
if (StringUtils.isNotEmpty(body)) {
|
||||
characters(body, escapeHtmlBody);
|
||||
}
|
||||
end("a");
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -65,13 +65,13 @@ public class SimpleTheme extends DefaultTheme {
|
||||
setName("simple");
|
||||
}
|
||||
|
||||
private class FactoryList extends ArrayList<TagHandlerFactory> {
|
||||
private static class FactoryList extends ArrayList<TagHandlerFactory> {
|
||||
|
||||
private static final long serialVersionUID = -1551895041394434032L;
|
||||
|
||||
public FactoryList(Class... classes) {
|
||||
public FactoryList(Class<?>... classes) {
|
||||
super();
|
||||
for (Class cls : classes) {
|
||||
for (Class<?> cls : classes) {
|
||||
add(new DefaultTagHandlerFactory(cls));
|
||||
}
|
||||
add(new DefaultTagHandlerFactory(XHTMLTagSerializer.class));
|
||||
|
||||
+9
-5
@@ -73,6 +73,7 @@ public class SubmitHandler extends AbstractTagHandler implements TagGenerator {
|
||||
public void generate() throws IOException {
|
||||
Map<String, Object> params = context.getParameters();
|
||||
String body = (String) params.get("body");
|
||||
Boolean escapeHtmlBody = (Boolean) params.get("escapeHtmlBody");
|
||||
|
||||
String type = StringUtils.defaultString((String) params.get("type"), "input");
|
||||
if ("button".equals(type)) {
|
||||
@@ -81,16 +82,19 @@ public class SubmitHandler extends AbstractTagHandler implements TagGenerator {
|
||||
characters(body, false);
|
||||
else if (params.containsKey("label")) {
|
||||
String label = (String) params.get("label");
|
||||
if (StringUtils.isNotEmpty(label))
|
||||
characters(label, false);
|
||||
if (StringUtils.isNotEmpty(label)) {
|
||||
characters(label, escapeHtmlBody);
|
||||
}
|
||||
}
|
||||
end("button");
|
||||
} else if ("image".equals(type)) {
|
||||
if (StringUtils.isNotEmpty(body))
|
||||
characters(body, false);
|
||||
if (StringUtils.isNotEmpty(body)) {
|
||||
characters(body, escapeHtmlBody);
|
||||
}
|
||||
end("input");
|
||||
} else
|
||||
} else {
|
||||
end("input");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+36
@@ -69,6 +69,42 @@ public class AnchorTest extends AbstractTest {
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
public void testEnableEscapeBody() {
|
||||
tag.setName("name_");
|
||||
tag.setHref("http://sometest.com?ab=10");
|
||||
tag.setEscapeHtmlBody(true);
|
||||
tag.evaluateParams();
|
||||
|
||||
map.putAll(tag.getParameters());
|
||||
context.getParameters().put("body", s("<i class='i-image'/>"));
|
||||
|
||||
theme.renderTag(getTagName(), context);
|
||||
theme.renderTag(getTagName() + "-close", context);
|
||||
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<a name='name_' id='name_' href='http://sometest.com?ab=10'><i class="i-image"/></a>");
|
||||
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
public void testDefaultDisabledEscapeBody() {
|
||||
tag.setName("name_");
|
||||
tag.setHref("http://sometest.com?ab=10");
|
||||
//tag.setEscapeHtmlBody(true);
|
||||
tag.evaluateParams();
|
||||
|
||||
map.putAll(tag.getParameters());
|
||||
context.getParameters().put("body", s("<i class='i-image'/>"));
|
||||
|
||||
theme.renderTag(getTagName(), context);
|
||||
theme.renderTag(getTagName() + "-close", context);
|
||||
|
||||
String output = writer.getBuffer().toString();
|
||||
String expected = s("<a name='name_' id='name_' href='http://sometest.com?ab=10'><i class='i-image'/></a>");
|
||||
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
Reference in New Issue
Block a user