ckeditor / ckeditor4

The best enterprise-grade WYSIWYG editor. Fully customizable with countless features and plugins.
https://ckeditor.com/ckeditor-4
Other
5.79k stars 2.48k forks source link

Coping and pasting widget throws error #717

Open Comandeer opened 7 years ago

Comandeer commented 7 years ago

Are you reporting a feature request or a bug?

Bug

Provide detailed reproduction steps (if any)

  1. Open http://ckeditor.com/ and scroll to "Article Editor" example
  2. Copy some text and widget with image.
  3. Paste them into editor.

Expected result

Widget is pasted correctly

Actual result

Only caption from the widget is pasted and error is thrown:

Uncaught TypeError: Cannot read property 'getAttribute' of null

Other details

mflorea commented 5 years ago

You can reproduce a similar problem with this:

Inspect the HTML and notice that there is an empty widget wrapper DIV right after the first image (the one you copied). This happens on Chrome but not on Firefox. I suspect that the difference between Chrome and Firefox is where the selection ends. In Firefox the selection probably ends right after the first image widget while in Chrome the selection ends inside the wrapper of the second image widget. As a result in Chrome you copy also the (empty) wrapper of the second image widget. This produces an invalid widget when pasted.

I get the following stack trace locally, with a custom unminified build of CKEditor (so the line numbers are not relevant):

Uncaught TypeError: Cannot read property 'attributes' of null
    at ckeditor.js:59423
    at CKEDITOR.htmlParser.element.forEach (ckeditor.js:20983)
    at CKEDITOR.htmlParser.element.forEach (ckeditor.js:20997)
    at CKEDITOR.htmlParser.element.forEach (ckeditor.js:20997)
    at CKEDITOR.htmlParser.element.forEach (ckeditor.js:20997)
    at Editor.<anonymous> (ckeditor.js:59388)
    at Editor.listenerFirer (ckeditor.js:465)
    at Editor.CKEDITOR.event.fire (ckeditor.js:611)
    at Editor.CKEDITOR.editor.fire (ckeditor.js:735)
    at CKEDITOR.htmlDataProcessor.toDataFormat (ckeditor.js:21710)

The line where it fails is this:

// If widget did not have data-cke-widget attribute before upcasting remove it.
if ( widgetElement.attributes[ 'data-cke-widget-keep-attr' ] != '1' )
    delete widgetElement.attributes[ 'data-widget' ];

widgetElement is null.

mflorea commented 5 years ago

This is probably related to #1300 , #1164 and #698 .