Fixed Copy & pasting may introduce unexpected new lines for browsers with old sessions

Xon

Well-known member
Affected version
2.1.4
Copy & pasting from Word, and things like Google Docs introduces unexpected formatting changes. This depends on if local storage has been initialized with older version of the XF editor.

The problem is fr-copied-text contains stale data that was never removed;
Code:
            try
            {
                copiedText = (ed.win.localStorage.getItem('fr-copied-text') || '').replace(/\s/g, '');
            }
            catch (e) {}
Nothing clears fr-copied-text, so if this was leftover from an old version of XF, this will result in unexpected behaviour.

For example copying & pasting what is;
Code:
This
Is
A
Test

Gets converted into this;
Code:
This

Is

A

Test

The issue is normalizePaste in js/xf/editor.js as it is doing cleanup which isn't consistent.

In Chrome (v76 and v77);
Word input;
<p>This</p><p>Is</p><p>A</p><p>Test</p>
Word output;
<p>This</p><p></p><p>Is</p><p></p><p>A</p><p></p><p>Test</p>
 
Last edited:
The issue you’re reporting here isn’t very clear at al, unfortunately.

For example you seem to mention different XF versions but I’m not sure which changes you’re referring to specifically or which versions I would need to use to reproduce this.

I haven’t yet looked into the changes in Chrome which I will do, but not currently sure how that’s relevant to your previous comments.

Put simply, can you please provide a clear and consistent reproduction case?
 
The local storage attributes fr-copied-text and fr-copied-html are set under some conditions by Froala at some stage. But they are not cleaned up as XenForo expects, as such a code path is triggered when it shouldn't be.

This results in duplicate new lines being unexpectedly inserted.
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.1.6).

Change log:
Fix potential incorrect behavior when pasting into the RTE from external sources. Improve behavior when pasting from Google Docs.
There may be a delay before changes are rolled out to the XenForo Community.
 
Worth noting that this was really 2 distinct issues.

First, there was an issue relating to fr-copied-text, though the issue was that we behaved differently when a value was there vs not. The behavior should simply be trying to detect if the paste is coming from what was copied within the editor via copiedText !== pastedText -- the length check was a bug.

In this instance, that meant that the pasted content could end up with fewer line breaks than expected. Notably, this applied to pastes from Word. Note that from Word, <p>Para 1</p><p>Para 2</p> should actually have <p></p> inserted between paragraphs because in Word, there are paragraph margins, where as in our RTE, there aren't.

The behavior with Google Docs is different. There, pressing enter just creates a single line break, but the paste is represented as <p> tags. However, at an earlier stage of the paste process, we can see that these have a style attribute that removes the paragraph margins. We now detect this and tag those <p> tags so that they won't get the line break inserted.

I've just rolled these changes out here, if you want to check how it behaves for you.
 
Top Bottom