[Pushed] The 'redundant tags on paste of unformatted text' browser-dependent SCEditor bug
#11
(2020-10-13, 10:55 AM)noyle Wrote:
(2020-10-13, 10:43 AM)Laird Wrote: In post #5 of the thread for another SCEditor bug, noyle referred to something that I have been thinking about re the three SCEditor bugs I've recently reported: that the solutions I've provided may not address "the root cause". I agree with noyle. Why? Because it seems that none of these three bugs are present in the current code for MyBB 1.9, which uses SCEditor version 1.4.7. MyBB's 1.8 feature branch, on which these bugs are present, uses SCEditor version 2.1.3. The root cause, then, is presumably among whatever changes took place between SCEditor version 1.4.7 and SCEditor version 2.1.3, and/or, perhaps, the additional SCEditor-related Javascript files that MyBB provides and has updated since 1.9 was branched. I haven't (yet?) though dug in to try to identify those changes.

Thanks for the investigation!

Don't know if @effone or @JordanMussi has any thoughts about this editor issue.

No worries!

I've now dug much deeper into this.

TL;DR: The fixes I've provided for these three bugs seem to be the best way to solve them.

First, a correction. As quoted above, I claimed that none of these three bugs is present in the current code for MyBB 1.9. That's not quite correct:

  1. The bug of this thread (and the related reduced-size-on-paste bug) is present under at least the Microsoft Edge browser even for MyBB 1.9 (but not under Chrome or Firefox).
  2. The double-quotes-in-fonts bug doesn't seem to be present only because everything from the first double-quote of the first double-quoted font simply gets deleted from the font list (leaving a trailing comma) on switching out of Source mode. This is because line 260 of jscripts/bbcodes_sceditor.js in the 1.9 branch has not yet had the fix of the current 1.8 branch applied to it: wrapping attrs.defaultattr in $.sceditor.escapeEntities(). The double-quotes are thus unescaped and literal, so those lines 259-261 create a tag something like this: <font face="Font1, "Font2 enclosed in double-quotes", Font3">Content</font>. The face attribute is thus terminated at the first internal double-quote prior to Font2, and its value becomes Font1, (and then the browser generates some unintended but harmless other attributes based on the remainder of the attribute's intended value).

As best I can tell, the double-quote bug has always been around, it just hadn't been noticed much. There seems to be no hope of reverting changes in SCEditor to solve this bug, and the solutions discussed in its thread seem best.

The SCEditor commit that introduced the problem to which this thread is dedicated as a bug for Chrome (recall that it doesn't affect Firefox, and was already present as a bug on Microsoft Edge) is commit a4f7163 of 15 November 2016: Improve paste filtering.

That commit fixed the horrible kludge between lines 1417 and 1451 of src/lib/SCEditor.js, in which the existing elements of the editor were saved to prePasteContent, and then the editor element was polled for new content, which, when it arrived, was stored to a new div element with variable name pastearea, after which the editor's original contents were restored from prePasteContent, and pastearea was passed to the handlePasteData() function, which used pastearea.innerHTML to determine which HTML was pasted.

The commit's fix uses the clipboard instead - a much more appropriate and elegant solution, and one that we ought not to revert.

The behaviour of the different browsers pre- and post-commit a4f7163 when unformatted text in the editor is copied and then pasted back into the editor seems to be as follows:
  • Chrome pre-a4f7163: innerHTML doesn't include any style attributes, and so MyCode tags are not generated.
  • Chrome post-a4f7163: the pasted HTML accessed via the browser's clipboard does include style attributes, and so the annoyingly redundant MyCode tags are generated.
  • Microsoft Edge: in both the innerHTML and clipboard scenarios, style attributes are included, and so the redundant MyCode tags are generated both pre- and post-commit a4f7163.
  • Firefox: the opposite of Microsoft Edge - in neither the innerHTML nor the clipboard scenario are style attributes included, and so no MyCode tags are generated either pre- or post-commit a4f7163.

Plainly, there is no hope here either of reverting changes in SCEditor to solve this bug, so, right now, the solution I've offered above seems to be the best approach.
Reply
#12
Hi,

Thank you for your report. We have pushed this issue to our Github repository for further analysis where you can track our commits and progress with fixing this bug. Discussions regarding this bug may also take place there too.

Follow this link to visit the issue on Github: https://github.com/mybb/mybb/issues/4184

Thanks for contributing to MyBB!

Regards,
The MyBB Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)