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
This commit is contained in:
Brian Clozel 2016-03-03 16:48:17 +01:00
parent 36e2dd90a7
commit 44c32128dc
2 changed files with 13 additions and 3 deletions

View File

@ -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;
}

View File

@ -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