Skip to content
Advertisement

Line endings in a form textarea

Morning,

When you post a form which has a textarea, what line endings are used? rn, n or like local files does it depend on the OS?

I am tryring to find an RFC or W3C spec or something, or is it different based on OS/browser? Got a link?

eg

<textarea name="message">This is
my
message
</textarea>

Would it be

This isrn
myrn
messagern

or

This isn
myn
messagen

and is it a standard or different based on browser/os. Proof?

I am not worried about the textarea content before it’s sent to the server, but the actual variable contents in PHP/server side.

Advertisement

Answer

This information can found in the HTML5 spec. It says that for the textarea element:

… there is the form submission value. It is normalized so that line breaks use U+000D CARRIAGE RETURN “CRLF” (U+000A) character pairs, and in addition, if necessary given the element’s wrap attribute, additional line breaks are inserted to wrap the text at the given width.

The element’s value is defined to be the element’s raw value with the following transformation applied:

Replace every occurrence of a “CR” (U+000D) character not followed by a “LF” (U+000A) character, and every occurrence of a “LF” (U+000A) character not preceded by a “CR” (U+000D) character, by a two-character string consisting of a U+000D CARRIAGE RETURN “CRLF” (U+000A) character pair.

If the element’s wrap attribute is in the Hard state, insert U+000D CARRIAGE RETURN “CRLF” (U+000A) character pairs into the string using a UA-defined algorithm so that each line has no more than character width characters. For the purposes of this requirement, lines are delimited by the start of the string, the end of the string, and U+000D CARRIAGE RETURN “CRLF” (U+000A) character pairs.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement