Ensure consistent ButtonTag value attribute processing

Closes gh-37017
This commit is contained in:
Sébastien Deleuze
2026-07-08 15:08:51 +02:00
parent c08e5e9c1c
commit ed13afa0d4
2 changed files with 18 additions and 1 deletions
@@ -67,6 +67,7 @@ import org.springframework.web.servlet.support.RequestDataValueProcessor;
* </table>
*
* @author Rossen Stoyanchev
* @author Sebastien Deleuze
* @since 3.1
*/
@SuppressWarnings("serial")
@@ -152,7 +153,8 @@ public class ButtonTag extends AbstractHtmlElementTag {
*/
protected void writeValue(TagWriter tagWriter) throws JspException {
String valueToUse = (getValue() != null ? getValue() : getDefaultValue());
tagWriter.writeAttribute("value", processFieldValue(getName(), valueToUse, getType()));
tagWriter.writeAttribute("value",
processFieldValue(getName(), getDisplayString(valueToUse), getType()));
}
/**
@@ -27,6 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rossen Stoyanchev
* @author Sebastien Deleuze
*/
class ButtonTagTests extends AbstractFormTagTests {
@@ -58,6 +59,20 @@ class ButtonTagTests extends AbstractFormTagTests {
assertAttributeNotPresent(output, "disabled");
}
@Test
void value() throws Exception {
this.tag.setValue("\"My Button\"");
assertThat(this.tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
assertThat(this.tag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
String output = getOutput();
assertTagOpened(output);
assertTagClosed(output);
assertContainsAttribute(output, "value", "&quot;My Button&quot;");
}
@Test
void disabled() throws Exception {
this.tag.setDisabled(true);