From 44c32128dcdbd4fc848ae0873d4a6aa84383569c Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Thu, 3 Mar 2016 16:48:17 +0100 Subject: [PATCH] Add newline at the beginning of textarea JSP tags This commit adds a newline char at the beginning of textarea tags values. As per the HTML 4.01 spec (and browsers behavior), a line break following a start tag is ignored. This can lead to Spring's textarea tag to ignore a line break char at the beginning of a tag value. See https://www.w3.org/TR/html401/appendix/notes.html#notes-line-breaks Issue: SPR-13503 --- .../web/servlet/tags/form/TextareaTag.java | 4 ++-- .../web/servlet/tags/form/TextareaTagTests.java | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/TextareaTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/TextareaTag.java index 09539fbbb8..16987862c2 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/TextareaTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/TextareaTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -98,7 +98,7 @@ public class TextareaTag extends AbstractHtmlInputElementTag { writeOptionalAttribute(tagWriter, COLS_ATTRIBUTE, getCols()); writeOptionalAttribute(tagWriter, ONSELECT_ATTRIBUTE, getOnselect()); String value = getDisplayString(getBoundValue(), getPropertyEditor()); - tagWriter.appendValue(processFieldValue(getName(), value, "textarea")); + tagWriter.appendValue("\r\n" + processFieldValue(getName(), value, "textarea")); tagWriter.endTag(); return SKIP_BODY; } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/TextareaTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/TextareaTagTests.java index 503262d46b..24b686eca5 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/TextareaTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/TextareaTagTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -121,6 +121,16 @@ public class TextareaTagTests extends AbstractFormTagTests { assertBlockTagContains(output, "12.34f"); } + @Test + public void firstNewLine() throws Exception { + this.tag.setPath("name"); + this.tag.setReadonly(true); + + assertEquals(Tag.SKIP_BODY, this.tag.doStartTag()); + String output = getOutput(); + assertBlockTagContains(output, "\r\nRob"); + } + @Override protected TestBean createTestBean() { // set up test data