Opened 6 years ago

Last modified 2 years ago

#11562 confirmed Bug

allowedContent = true results in JS error when inserting elements

Reported by: Tyler Owned by:
Priority: Normal Milestone:
Component: Core : Editable Version: 4.0
Keywords: Cc:

Description (last modified by Jakub Ś)

When config.allowedContent = true; is set, the editor throws a JS error when inserting content (such as an image) into any unknown element. A simple test case is this:

<nobr>a</nobr>

Steps to reproduce: With the above content entered into the editor, set the cursor focus to be inside the unknown tag, then insert an image.

Inside core/editable.js, the function extractNodesData throws an error trying to look-up the allowed names for this element.

This is invalid HTML, so it is a user error, but the config.allowedContent = true; prevents it from being filtered out (as it should). We've seen it pop-up when users are copy and pasting content from other sources. So at a minimum, I think the editor should handle this case in some way.

My suggestion is when allowedContent is set to true, the editor should treat all unknown tags as a semantically meaning-less tag, perhaps inheriting the allowedNames from DIV elements.

I would be willing to submit a fix with the above suggestion, or implement another suggested fix if needed.

Thanks

Chrome error message:

Uncaught TypeError: Cannot read property 'img' of undefined ckeditor.js:319
c ckeditor.js:319
(anonymous function) ckeditor.js:326
CKEDITOR.editable.CKEDITOR.tools.createClass.proto.insertHtml ckeditor.js:300
(anonymous function) ckeditor.js:306
h ckeditor.js:10
CKEDITOR.event.CKEDITOR.event.fire ckeditor.js:11
CKEDITOR.editor.CKEDITOR.editor.fire ckeditor.js:13
CKEDITOR.tools.extend.insertHtml ckeditor.js:225
$.extend.editor.paste

Edit: This issue is about CKEditor throwing error if DTD was not extended.

Attachments (1)

11562.html (727 bytes) - added by Piotrek Koszuliński 6 years ago.

Download all attachments as: .zip

Change History (5)

Changed 6 years ago by Piotrek Koszuliński

Attachment: 11562.html added

comment:2 Changed 6 years ago by Piotrek Koszuliński

Status: newconfirmed
Version: 4.3.24.0

It's not a DUP of #10340. The issue can be reproduced on 11562.html but if CKEDITOR.dtd is correctly extended before editor initialization, everything works. Try e.g. placing this before CKEDITOR.replace:

CKEDITOR.dtd.nobr = { img:1,'#':1 };

Now there's no error. And #10340 is about cases in which DTD caching makes it impossible to extend it after loading CKEditor source.

However, I agree that CKEditor could not throw error if DTD was not extended. Not in every scenario it's predictable what will be inserted into editor and it's not a problem to default use some default DTD (span's or p's) when element cannot be found.

Last edited 2 years ago by Jakub Ś (previous) (diff)

comment:3 Changed 2 years ago by Jakub Ś

Description: modified (diff)

comment:4 Changed 2 years ago by Jakub Ś

Description: modified (diff)

comment:5 Changed 2 years ago by Jakub Ś

Related issues: #10340, #14717, #14615.

Last edited 2 years ago by Jakub Ś (previous) (diff)
Note: See TracTickets for help on using tickets.
© 2003 – 2019 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy