Closed Bug 1923829 Opened 16 days ago Closed 8 days ago

innerText randomly removes newline of `white-space: pre-line`

Categories

(Core :: Layout: Text and Fonts, defect)

Firefox 133
defect

Tracking

()

RESOLVED FIXED
133 Branch
Tracking Status
firefox133 --- fixed

People

(Reporter: m.englisch, Assigned: jfkthame)

References

Details

Attachments

(2 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0

Steps to reproduce:

  1. Open the showcase.html (attached) in Firefox.
  2. In the contenteditable table field, just add any char after "three"

(And then read it's content using innerText.)

Actual results:

innerText returns:
"one
twothree"

Tested to fail on version:
133.0a1 (2024-10-09)
132.0b5
128.3.1esr

Expected results:

innerText should return:
"one
two
three"

There is no reason for innerText remove the newline between two and three.

The Bugbug bot thinks this bug should belong to the 'Core::DOM: Editor' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → DOM: Editor
Product: Firefox → Core

Can confirm this behaviour in Fireofx. Can repro on a build from Jan2021, so not a new regression.
Chrome prints "one two three".

Status: UNCONFIRMED → NEW
Ever confirmed: true

Indeed, I reproduce this bug too, but it seems that it's not related that whether the content is editable or not. And I reproduce this only with pre-line but not with pre. It seems that this is a bug in nsTextFram::GetRenderedText() because GetInnerText() implementation in the DOM module does not build the result string by itself.

Component: DOM: Editor → Layout: Text and Fonts
Summary: innerText randomly removes newline when editing contenteditable → innerText randomly removes newline of `white-space: pre-line`

Yes, I think this is a bug in nsTextFrame::GetRenderedText(). Specifically, it iterates over a chain of continuation frames (the loop here) with textFrame being the current continuation to be examined. But a few times inside that loop, like here, it calls nsTextFrame methods (like HasSignificantTerminalNewline()) without the textFrame-> prefix, and so it's actually calling the method on the primary frame (this), not the continuation that it's trying to handle.

Assignee: nobody → jfkthame
Severity: -- → S3

For clarity, we refactor body of the loop-over-continuations in
nsTextFrame::GetRenderedText into a helper method AppendRenderedText
that handles a single continuation in the chain.

This avoids the footgun of an nsTextFrame method iterating over its
continuations (using the textFrame variable) but potentially calling
methods of the primary frame within the loop, instead of the current
frame being processed.

Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f2f6cefad4a1 Check the correct frame when iterating over continuations in nsTextFrame::GetRenderedText. r=dshin
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/48678 for changes under testing/web-platform/tests

Marcel Englisch: Thank you for your bug report. I have a question about the reported case. Your testcase specifies white-space: pre-line to an editable element. That means that if users types multiple white-spaces consecutively, browsers replace some white-spaces with non-breakable spaces (a.k.a., NBSP,  , U+00A0) to make the consecutive white-spaces visible. Therefore, I didn't assume that web developers want to use pre-line with contenteditable. So, my question is, why do you want to use pre-line rather than normal, pre and pre-wrap?

Flags: needinfo?(m.englisch)
Status: NEW → RESOLVED
Closed: 8 days ago
Resolution: --- → FIXED
Target Milestone: --- → 133 Branch
Upstream PR merged by moz-wptsync-bot
Upstream PR merged by moz-wptsync-bot

You're very welcome. Glad I could help.
To your question: I had an web app that uses innerHTML and encodes/decodes all by itself. Last week I experimented using innerText and white-space as it fits better my use case. It was pre-line because I didn't understand how exactly white-space-values work at that time. Shortly after I reported this bug I noticed that pre-wrap is the correct value for my use case. Impressive that you noticed that even without knowing what I'm doing.
Thank you for your work and fast response!

Flags: needinfo?(m.englisch)

Thank you for explaining the detail. Okay, then, we don't need to fix bug 1925428 before shipping contenteditable=plaintext-only.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: