Copying \r\n inside <pre> converts to \n\n
Categories
(Core :: DOM: Serializers, defect)
Tracking
()
People
(Reporter: saschanaz, Assigned: edgar)
References
(Regression)
Details
(4 keywords)
User Story
platform-scheduled:2025-09-30 user-impact-score:600
Attachments
(6 files, 3 obsolete files)
- Open the attachment
- Copy the content
- Paste it somewhere
Expected: Single newline per line
Actual: Double newlines per line
| Reporter | ||
Updated•5 years ago
|
| Reporter | ||
Updated•5 years ago
|
| Reporter | ||
Comment 1•5 years ago
•
|
||
This is confusing.
| Reporter | ||
Comment 2•5 years ago
|
||
This is confusing, EncodeForTextUnicode() tries encoding the text with the mime type text/html instead of text/plain. The comment says:
// note that we assign text/unicode as mime type, but in fact
// nsHTMLCopyEncoder ignore it and use text/html or text/plain depending where
// the selection is. if it is a selection into input/textarea element or in a
// html content with pre-wrap style : text/plain. Otherwise text/html. see
// nsHTMLCopyEncoder::SetSelection
I'm not sure why the copy would ever be text/html even when it's not pre-wrap style. This comment is wrong anyway, as it only becomes text/plain for <input> and <textarea> but not for pre-wrap style. That means, copying <pre> actually uses text/html.
The second confusing part is that EncodeForTextUnicode() tries encoding in raw-mode first (which does not affect newlines) and then retries in non-raw-mode, which causes the bug by incorrectly replacing \n with \r\n, making \r\n to \r\r\n. Why try twice?
Emilio, do you happen to have some idea about this, as one of the relevant functions has your FIXME comment?
Comment 3•5 years ago
|
||
Not really, that FIXME is about assuming that all the selection is in the first selection range, which is not true for table selection for example.
| Reporter | ||
Comment 4•5 years ago
|
||
Oops, okay. Keeping pinging semi-randomly based on commit history...
Mirko, it seems you refactored some of the code, do you have some idea about the mime type thing?
(In reply to Kagami :saschanaz from comment #2)
This is confusing,
EncodeForTextUnicode()tries encoding the text with the mime typetext/htmlinstead oftext/plain. The comment says:// note that we assign text/unicode as mime type, but in fact // nsHTMLCopyEncoder ignore it and use text/html or text/plain depending where // the selection is. if it is a selection into input/textarea element or in a // html content with pre-wrap style : text/plain. Otherwise text/html. see // nsHTMLCopyEncoder::SetSelectionI'm not sure why the copy would ever be
text/htmleven when it's not pre-wrap style. This comment is wrong anyway, as it only becomestext/plainfor<input>and<textarea>but not for pre-wrap style.
I'm not sure how relevant it is, but in another case text/plain is set too.
That means, copying
<pre>actually usestext/html.
The second confusing part is that
EncodeForTextUnicode()tries encoding in raw-mode first (which does not affect newlines) and then retries in non-raw-mode, which causes the bug by incorrectly replacing\nwith\r\n, making\r\nto\r\r\n. Why try twice?
I'm unfamiliar with this detail, it needs investigation.
Emilio, do you happen to have some idea about this, as one of the relevant functions has your FIXME comment?
Updated•5 years ago
|
May be this behavior is also related to this bug.
Steps to reproduce
- Go to IEEE Explore page and open any research paper. For example: https://ieeexplore.ieee.org/document/7919538
- Click on
Cite thisbutton - Select BibTex option
- Copy BibTex content using mouse and keyboard that's select text using mouse and the press
Ctrl+C - Paste it in any text editor
Actual ouput
Every sentence ends with an extra new line.
Expected output
There shouldn't be any extra new line after each sentence.
Additional
Like 152844#c4 example, I cannot reproduce this bug in HTML based editors like Librewriter; seems like problem is with text serialization.
| Reporter | ||
Comment 7•5 years ago
|
||
No immediate plan to work on this, please feel free to take it.
Updated•1 year ago
|
Comment 9•1 year ago
•
|
||
This page ( https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q12303673327 ) is also affected .
Chrome works as expected.
Comment 10•1 year ago
|
||
Regression window:
https://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=92fe907ddac8&tochange=bbe5086163c9
Suspect: Bug 731896
Comment 11•1 year ago
|
||
Set release status flags based on info from the regressing bug 731896
:hsivonen, since you are the author of the regressor, bug 731896, could you take a look?
For more information, please visit BugBot documentation.
Comment 12•1 year ago
|
||
You are supposed to use only LF in the DOM. On Windows, in-DOM LF gets converted to CRLF to match Windows convention. Putting a CR in the DOM is bad, and the outcome follows logically from the previous sentence, since CR stays as-is and LF gets replaced with CRLF.
From a logical point of view, the behavior described in comment 0 is as expected. However, if Web pages run into this in a way that users perceive as a problem that does not occur in Chrome (per comment 9), it makes sense to find out what Chrome does and start doing that.
Updated•1 year ago
|
Updated•1 year ago
|
Comment 13•1 year ago
|
||
Updated•1 year ago
|
Updated•1 year ago
|
| Assignee | ||
Updated•8 months ago
|
| Assignee | ||
Comment 14•8 months ago
|
||
On macOS, the \r\n is replaced to \n\n on Firefox, whereas it is replaced to \n on Chromium. So it worth to test each platform, they could have different behavior.
| Assignee | ||
Comment 15•8 months ago
|
||
There are two main actions involved,
- Serialize selection into plaintext and put into system clipboard
- Text editor read the clipboard plaintext data and insert the text.
For the second action, all browsers behave the same on each platform to turn the platform line break into DOM line break, e.g.
- \r\n ---> \n
- \r ---> \n
But on the first steps, Firefox behave differently than other browsers,
Mac:
| Firefox | Chrome | Safari | |
|---|---|---|---|
| \r | \n | \r | \r |
| \n | \n | \n | \n |
| \r\r | \n\n | \r\r | \r\r |
| \r\n | \n\n | \r\n | \r\n |
| \n\r | \n\n | \n\r | \n\r |
| \n\n | \n\n | \n\n | \n\n |
| \r\r\r | \n\n\n | \r\r\r | \r\r\r |
| \r\r\n | \n\n\n | \r\r\n | \r\r\n |
| \r\n\r | \n\n\n | \r\n\r | \r\n\r |
| \r\n\n | \n\n\n | \r\n\n | \r\n\n |
| \n\r\r | \n\n\n | \n\r\r | \n\r\r |
| \n\r\n | \n\n\n | \n\r\n | \n\r\n |
| \n\n\r | \n\n\n | \n\n\r | \n\n\r |
| \n\n\n | \n\n\n | \n\n\n | \n\n\n |
Linux:
| Firefox | Chrome | |
|---|---|---|
| \r | \n | \r |
| \n | \n | \n |
| \r\r | \n\n | \r\r |
| \r\n | \n\n | \r\n |
| \n\r | \n\n | \n\r |
| \n\n | \n\n | \n\n |
| \r\r\r | \n\n\n | \r\r\r |
| \r\r\n | \n\n\n | \r\r\n |
| \r\n\r | \n\n\n | \r\n\r |
| \r\n\n | \n\n\n | \r\n\n |
| \n\r\r | \n\n\n | \n\r\r |
| \n\r\n | \n\n\n | \n\r\n |
| \n\n\r | \n\n\n | \n\n\r |
| \n\n\n | \n\n\n | \n\n\n |
Windows:
| Firefox | Chrome | |
|---|---|---|
| \r | \n | \r |
| \n | \n | \r\n |
| \r\r | \n\n | \r\r |
| \r\n | \n\n | \r\n |
| \n\r | \n\n | \r\n\r |
| \n\n | \n\n | \r\n\r\n |
| \r\r\r | \n\n\n | \r\r\r |
| \r\r\n | \n\n\n | \r\r\n |
| \r\n\r | \n\n\n | \r\n\r |
| \r\n\n | \n\n\n | \r\n\r\n |
| \n\r\r | \n\n\n | \r\n\r\r |
| \n\r\n | \n\n\n | \r\n\r\n |
| \n\n\r | \n\n\n | \r\n\r\n\r |
| \n\n\n | \n\n\n | \r\n\r\n\r\n |
| Assignee | ||
Comment 16•8 months ago
|
||
So on Linux and Mac, Safari and Chrome doesn't change the DOM text while serializing. And on Windows, Chrome convert LF to CRLF for Windows convention.
Firefox always covert CR to LF. It is handled in nsPlainTextSerializer.
| Assignee | ||
Comment 17•8 months ago
|
||
selection.toString() has similar issue, but Chrome doesn't convert LF to CRLF even on Windows.
| Assignee | ||
Updated•8 months ago
|
| Assignee | ||
Comment 18•8 months ago
|
||
| Assignee | ||
Updated•8 months ago
|
Updated•8 months ago
|
Updated•8 months ago
|
| Assignee | ||
Comment 19•8 months ago
|
||
Comment 20•8 months ago
|
||
Comment on attachment 9513584 [details]
Bug 1650720 - Make nsIContentSerializer::AppendText() and AppendCDATASection() take Text;
Revision D265012 was moved to bug 1989141. Setting attachment 9513584 [details] to obsolete.
Updated•8 months ago
|
Updated•7 months ago
|
| Assignee | ||
Comment 21•7 months ago
|
||
| Assignee | ||
Comment 22•7 months ago
|
||
Updated•7 months ago
|
| Assignee | ||
Comment 23•7 months ago
|
||
| Assignee | ||
Comment 24•7 months ago
|
||
| Assignee | ||
Comment 25•7 months ago
|
||
Updated•7 months ago
|
Updated•6 months ago
|
Updated•6 months ago
|
Updated•6 months ago
|
Comment 26•6 months ago
|
||
Comment on attachment 9519423 [details]
Bug 1650720 - Part 1: Move some serializer mochitest tests to dom/serializers/tests/; r?masayuki
Revision D268242 was moved to bug 1997661. Setting attachment 9519423 [details] to obsolete.
Updated•6 months ago
|
Updated•6 months ago
|
Updated•6 months ago
|
| Assignee | ||
Comment 27•6 months ago
|
||
Updated•6 months ago
|
| Assignee | ||
Comment 28•6 months ago
|
||
| Assignee | ||
Comment 29•6 months ago
|
||
Comment 30•6 months ago
|
||
Comment 31•6 months ago
|
||
Comment 32•6 months ago
|
||
Backed out for causing mochitest failures @ test_aboutmemory3.xhtml
| Assignee | ||
Comment 37•6 months ago
|
||
| Assignee | ||
Updated•6 months ago
|
Comment 38•6 months ago
|
||
Comment 40•6 months ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/f498fb9dee3e
https://hg.mozilla.org/mozilla-central/rev/cda95ac89f88
https://hg.mozilla.org/mozilla-central/rev/165dd0e12faf
https://hg.mozilla.org/mozilla-central/rev/68933e8da80f
Updated•6 months ago
|
Description
•