From ed13afa0d402fd66a7054b1b0cac2d3095454848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Wed, 8 Jul 2026 15:08:51 +0200 Subject: [PATCH] Ensure consistent ButtonTag value attribute processing Closes gh-37017 --- .../web/servlet/tags/form/ButtonTag.java | 4 +++- .../web/servlet/tags/form/ButtonTagTests.java | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java index b3908e46f6a..9ecf8fc335e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java @@ -67,6 +67,7 @@ import org.springframework.web.servlet.support.RequestDataValueProcessor; * * * @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())); } /** diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/ButtonTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/ButtonTagTests.java index c4c3431fccb..82f9effc565 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/ButtonTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/ButtonTagTests.java @@ -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", ""My Button""); + } + @Test void disabled() throws Exception { this.tag.setDisabled(true);