Skip to content

Pasting individual list elements from Firefox on Windows fails #3415

Closed
@jackwickham

Description

Type of report

Bug

Provide detailed reproduction steps (if any)

  1. 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)

  1. 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">&nbsp;</span>
<li>
		B
	</li>
	<li>
		C
	</li>
<span data-cke-marker="1">&nbsp;</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">&nbsp;</span>
<ul>
    <li>
        B
    </li>
    <li>
        C
    </li>
    <span data-cke-marker="1">&nbsp;</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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    browser:firefoxThe issue can only be reproduced in the Firefox browser.plugin:clipboardThe plugin which probably causes the issue.status:confirmedAn issue confirmed by the development team.type:bugA bug.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions