[Webkit-unassigned] [Bug 240566] New: innerText from element with "white-space: pre-line" incorrectly removes line breaks

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed May 18 01:41:29 PDT 2022


https://bugs.webkit.org/show_bug.cgi?id=240566

            Bug ID: 240566
           Summary: innerText from element with "white-space: pre-line"
                    incorrectly removes line breaks
           Product: WebKit
           Version: Safari 15
          Hardware: All
                OS: Unspecified
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: JavaScriptCore
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: ik at rejh.nl

Created attachment 459530

  --> https://bugs.webkit.org/attachment.cgi?id=459530&action=review

Testcase v101

When I retrieve the innerText value of an element that has "white-space: pre-line;", the resulting string does not contain any line breaks (\n).

The following changes/variations do preserve line breaks when retrieving :

* Retrieving textContent instead of innerText
* Using "pre-wrap"
* A combination of the above

... but these have side-effects, as it causes slightly different behavior.

According to MDN, newlines should be preserved for both pre-line and pre-wrap:
https://developer.mozilla.org/en-US/docs/Web/CSS/white-space#values

See attached testcase, also available here:
https://testcase.rejh.nl/webkit-pre-line-innertext/

* The first div has "white-space: pre-line"
* The second div has "pre-wrap"
* Use the buttons to print innerText or textContent to the console

Note: I've tested this in Safari, Chrome and Firefox. Only Chrome returns the same result for innerText and textContent when "pre-line" is set, preserving line breaks. Firefox seems to also strip the newline characters when retrieving innerText while preserving them for textContent. If the intended/spec'd behavior of innerText is to remove line breaks for "pre-line", I'll happily file a bug @ Chrome :)

Thanks!

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20220518/3a2d2d86/attachment.htm>


More information about the webkit-unassigned mailing list