New issue
Advanced search Search tips

Issue 705478 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner: ----
Closed: Oct 22
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug

Blocking:
issue 573309



Sign in to add a comment

innerText adding '\n' to Textarea (not display:none) should make a '<br>'

Reported by testxxxx...@gmail.com, Mar 27 2017

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36

Steps to reproduce the problem:
1. <textarea id="t01" style="display:none"></textarea>

2. document.querySelector('#t01').innerText = '555\n666';

3. document.querySelector('#t01').outerHTML will be:

"<textarea id="t01" style="display:none">555<br>666</textarea>"

What is the expected behavior?
document.querySelector('#t01').outerHTML will be:

"<textarea id="t01" style="display:none">555
666</textarea>"

What went wrong?
In the textarea, '\n' was changed to '<br>';

If I set textarea's style: "display:block", It's ok.

Did this work before? N/A 

Chrome version: 57.0.2987.110  Channel: n/a
OS Version: 10.0
Flash Version: Shockwave Flash 25.0 r0

This issue maybe is in the webkit, but I don't know.
 

Comment 1 by tkent@chromium.org, Mar 27 2017

Blocking: 573309
Components: -Blink Blink>HTML Blink>Forms
Labels: Hotlist-Interop
Status: Available (was: Unconfirmed)
Summary: innerText adding '\n' to Textarea (not display:none) should make a '<br>' (was: Use innerText() add '\n' to Textarea (display:none) will get the '<br>')
Safari and Firefox has the same behavior.

This behavior is defined by the HTML standard. The behavior without display:none is a bug according to it.

https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute:dom-innertext-3

Please use textContent or defaultValue or value setter instead of innerText setter.

Thanks very much.

Can I think that: with display:block, the browser operation is to keep the old HTML page compatible?

Comment 3 by tkent@chromium.org, Mar 28 2017

> with display:block, the browser operation is to keep the old HTML page compatible?

Mainly for IE-compatibility.
Firefox inserts a <br> even with display:block.  So we can guess there are no many web site relying on this behavior.

I see. Thanks.
Project Member

Comment 6 by sheriffbot@chromium.org, Apr 2 2018

Labels: Hotlist-Recharge-Cold
Status: Untriaged (was: Available)
This issue has been Available for over a year. If it's no longer important or seems unlikely to be fixed, please consider closing it out. If it is important, please re-triage the issue.

Sorry for the inconvenience if the bug really should have been left as Available.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot

Comment 7 by tkent@chromium.org, Apr 2 2018

Labels: -Hotlist-Recharge-Cold
Status: Available (was: Untriaged)
Project Member

Comment 8 by bugdroid1@chromium.org, Oct 22

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/fa583784527c3c1575f1145d31c79c6733176d38

commit fa583784527c3c1575f1145d31c79c6733176d38
Author: Sunny <ratsunny@gmail.com>
Date: Mon Oct 22 05:50:45 2018

Align some set innerText behavior with standard

According to spec[1], when a string starts with CR/LF set as innerText,
the first child node should not be an empty text node. So we adjust the
logic in HTMLElement::TextToFragment to make sure it follows the spec.

Besides, same in spec[1], there is no special procedure for setting
innerText when the element is being rendered and styled as preserving
new line, so corresponding code was removed in this commit.

15 failed wpt tests could be passed after this change.

[1] https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute

Bug: 573309,  705478 
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng;luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I6765601a14c2e95cec3841e084046da79aca065c
Reviewed-on: https://chromium-review.googlesource.com/c/1266728
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601480}
[modify] https://crrev.com/fa583784527c3c1575f1145d31c79c6733176d38/third_party/WebKit/LayoutTests/external/wpt/html/dom/elements/the-innertext-idl-attribute/setter-expected.txt
[modify] https://crrev.com/fa583784527c3c1575f1145d31c79c6733176d38/third_party/blink/renderer/core/html/html_element.cc

Labels: Target-72
Status: Fixed (was: Available)

Sign in to add a comment