Pasting individual list elements from Firefox on Windows fails #3415
Description
Type of report
Bug
Provide detailed reproduction steps (if any)
- Copy a fragment of a list using Firefox on Windows. For example, given a list with elements A, B, C and D, copying just B and C will produce clipboard contents
<html><body>
<!--StartFragment--><li>
B
</li>
<li>
C
</li><!--EndFragment-->
</body>
</html>
(per https://evercoder.github.io/clipboard-inspector/ as well as dev tool stepping through)
- Paste this into a CKEditor instance
Expected result
The paste succeeds, inserting
- B
- C
Actual result
TypeError: maybeBlockData is undefined
Root cause
This error appears to be caused because within the clipboard plugin, in _stripHtml
, the regexes that strip the above snippet trim the <html>
, <body>
and <!--(Start|End)Fragment-->
, but they don't trim the whitespace between <body>
and <!--StartFragment-->
, and between <!--EndFragment-->
and </body>
. The trimmed result therefore has leading and trailing whitespace.
When this makes its way to core/editable.js, processDataForInsertion
, this triggers the leading/trailing whitespace check, so it is prepended and appended with a protection span, so it looks like
<span data-cke-marker="1"> </span>
<li>
B
</li>
<li>
C
</li>
<span data-cke-marker="1"> </span>
This is then parsed as HTML. As it stands it isn't valid HTML, because there are bare <li>
s without a <ul>
. When Firefox parses it, it fixes it up as well as it can, to produce HTML equivalent to
<span data-cke-marker="1"> </span>
<ul>
<li>
B
</li>
<li>
C
</li>
<span data-cke-marker="1"> </span>
</ul>
When you then trim the first and last elements of this, to drop the spans that are supposed to be leading and trailing, this deletes everything and causes the rest of the code to break.
Other details
- Browser: Firefox 69 (I believe it only started occurring in 68 or 69)
- OS: Windows 10 (this does not occur in Linux)
- CKEditor version: 4.6.0
- Installed CKEditor plugins: clipboard
Activity