Opened 8 years ago

Closed 4 years ago

#8627 closed Bug (fixed)

Textarea misses first line if empty (in display)

Reported by: sebastian.hillig Owned by: sebastian.hillig
Component: Forms Version: master
Severity: Normal Keywords: forms textarea
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

If you save a textarea with a leading empty line, the browser won't show you that line (when viewing that textarea a change form again). This is due to a behaviour that browsers (test FF, Safari on Mac and IE 7 on Win) ignore the first line-break within a textarea when displaying it. Therefore the patch only adds one line-break right after the opening textarea-tag

Attachments (1)

fix_textarea_disappearing_first_empty_line.diff (4.4 KB) - added by sebastian.hillig 8 years ago.
Patch, only adds a line-break, with corrected tests

Download all attachments as: .zip

Change History (11)

Changed 8 years ago by sebastian.hillig

Patch, only adds a line-break, with corrected tests

comment:1 Changed 8 years ago by sebastian.hillig

Component: UncategorizedForms
Keywords: textarea added
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 8 years ago by Malcolm Tredinnick

Resolution: wontfix
Status: newclosed

I'm not sure I like this. It changes the data without the user's consent. If you load a form, then save, then load again, then save again (e.g. whilst editing), blank lines keep getting added to your data.

comment:3 Changed 8 years ago by James Bennett

I really don't like this, because it silently corrupts the data in ways that will' screw with things people commonly use textareas for.

(as I was saying before Malcolm closed this out from under me)

comment:4 in reply to:  2 Changed 8 years ago by Thomas Kerpe

Replying to mtredinnick:

I'm not sure I like this. It changes the data without the user's consent. If you load a form, then save, then load again, then save again (e.g. whilst editing), blank lines keep getting added to your data.

In the wild the opposite happens (At least in Safari, Firefox, IE7, Opera, lynx and others). If you rely on lets say one or two newlines in front of other data in a textarea the first newline will get eaten on every save. I have not found a current browser yet that handles this different. Opera has even changed this behavior to ignore the first line: http://my.opera.com/community/forums/topic.dml?id=94823

Use for example FlatPage in admin enter some newlines in the textarea and then some other visible characters. Now hit "Save and continue editing" several times and watch the characters wandering upwards. In reverse entering something different to a newline will work fine. With that patch no additional newline is stored in the database.

The Spec is not 100% clear here but all major Browsers implement it on the same way.
http://www.w3.org/TR/html4/interact/forms.html#h-17.7

comment:5 Changed 8 years ago by Malcolm Tredinnick

milestone: 1.0post-1.0
Resolution: wontfix
Status: closedreopened
Triage Stage: UnreviewedDesign decision needed

We can look at this after 1.0. It's too late now to have time to test it thoroughly and it's a bit of an edge case (only affects leading blank lines). I'm worried that it will change things for, e.g., machine-processed data that uses HTML intelligently.

comment:6 Changed 8 years ago by Thomas Kerpe

For documentation:
Maybe this will help with that issue when someone is working or thinking on it later: http://www.toke.de/textarea-nl-testcase.html

comment:7 Changed 8 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:8 Changed 5 years ago by Luke Plant

Severity: Normal
Type: Bug

comment:9 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset
Patch needs improvement: set
Triage Stage: Design decision neededAccepted
UI/UX: unset

This seems just wrong, but I could confirm the bug. Given that all browsers behave consistently, we'd better add the CRLF.

The patch is stale.

comment:10 Changed 4 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: reopenedclosed

In 78f66691ee7974e0ca546f09573394395a68b443:

Fixed #8627 -- Prevented textareas to swallow first newline content

Browsers consider the first newline in textareas as some display
artifact, not real content. Hence they are not sending it back to
the server. If we want to keep initial newlines, we have to add one
when we render the textarea.
Thanks bastih for the report and initial patch.

Note: See TracTickets for help on using tickets.
Back to Top