Skip to content

Commit 44c3212

Browse files
committed
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
1 parent 36e2dd9 commit 44c3212

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/TextareaTag.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -98,7 +98,7 @@ protected int writeTagContent(TagWriter tagWriter) throws JspException {
9898
writeOptionalAttribute(tagWriter, COLS_ATTRIBUTE, getCols());
9999
writeOptionalAttribute(tagWriter, ONSELECT_ATTRIBUTE, getOnselect());
100100
String value = getDisplayString(getBoundValue(), getPropertyEditor());
101-
tagWriter.appendValue(processFieldValue(getName(), value, "textarea"));
101+
tagWriter.appendValue("\r\n" + processFieldValue(getName(), value, "textarea"));
102102
tagWriter.endTag();
103103
return SKIP_BODY;
104104
}

spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/TextareaTagTests.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -121,6 +121,16 @@ public void customBind() throws Exception {
121121
assertBlockTagContains(output, "12.34f");
122122
}
123123

124+
@Test
125+
public void firstNewLine() throws Exception {
126+
this.tag.setPath("name");
127+
this.tag.setReadonly(true);
128+
129+
assertEquals(Tag.SKIP_BODY, this.tag.doStartTag());
130+
String output = getOutput();
131+
assertBlockTagContains(output, "\r\nRob");
132+
}
133+
124134
@Override
125135
protected TestBean createTestBean() {
126136
// set up test data

0 commit comments

Comments
 (0)