Opened 3 years ago

Closed 3 years ago

Last modified 2 years ago

#14861 closed Bug (invalid)

In Chrome HTML comments are copied in protected form

Reported by: Eugene Owned by:
Priority: Normal Milestone:
Component: General Version:
Keywords: Cc:


Steps to reproduce:

  1. Open HTML source
  2. Enter a<!--comment-->b
  3. Return to WYSIWYG mode
  4. Select the entire contents of CKEDITOR (ab)
  5. In any way, inspect clipboard contents

Expected result: a<!--comment-->b
Actual result: a<!--{cke_protected}{C}%3C!%2D%2Dcomment%2D%2D%3E-->b

OS: Windows 7 Professional
Browser: Google Chrome 52.0.2743.116 m
CKEditor version: (4.5.11 (Standard))

Attachments (1)

ckeditor 14861.png (91.5 KB) - added by Eugene 3 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 3 years ago by Jakub Ś

Resolution: invalid
Status: newclosed

You TC is missing step 6 which is: I get data from editor with the help of getData method (which is the only walid way to extrac clean HTML from the editor) and everything is working fine.

comment:2 Changed 3 years ago by Eugene

Sorry, I missed one step indeed. After selecting contents at step 4, copy it, e.g. with Ctrl-C.

The problem is that the copied HTML contains protected HTML comments. A user does not necessarily paste this HTML into a CKEDITOR, so the protected HTML comments might end up somewhere where ordinary HTML comments are expected.

comment:3 Changed 3 years ago by Jakub Ś

I don't quite get this last comment.

When you copy in wysiwyg mode you just get ab and when you switch to source mode you get <p>a<!--comment-->b</p>.
How were you able to copy HTML with protected comments? If you were copying from dev-tools then this is invalid. You need to switch to source mode and copy HTML from there.

comment:4 in reply to:  3 Changed 3 years ago by Eugene

Replying to j.swiderski:

When you copy in wysiwyg mode you just get ab

This isn't completely true. The clipboard indeed contains ab in its text channel, so if you paste into a usual text field, or Microsoft Word, or virtually any piece of software that accepts primarily text, everything is fine - ab gets inserted.

But in HTML channel clipboard actually contains a<!--{cke_protected}{C}%3C!%2D%2Dcomment%2D%2D%3E-->b. You can see that, for example, using this software: (not an ad). If you paste it somewhere, where HTML is expected, this HTML with protected comments will be inserted. I am going to attach some screenshots to clarify that.

Changed 3 years ago by Eugene

Attachment: ckeditor 14861.png added

comment:5 Changed 3 years ago by Eugene

Here are

  1. CKEDITOR demo page
  2. clipboard viewer showing copied protected HTML comment
  3. about:blank page opened in Chrome, where I then opened DevTools and added contenteditable attribute to body, closed DevTools, performed paste and opened DevTools again to illustrate what is inserted

I understand that pasting into a contenteditable element which is not a CKEDITOR is probably an uncommon scenarion. It is just a case when clipboard's HTML content is given priority over text content, and it illustrates that clipboard's HTML content is incorrect.

Update: fixed typos

Last edited 3 years ago by Eugene (previous) (diff)

comment:6 Changed 3 years ago by Jakub Ś

In Firefox on the other way, you will not see any comments.

I'm sorry but such case is not supported. If you need HTML, please switch to source mode and get it from there. If you need text, please copy from wysiwyg. You can't copy HTML from wysiwyg because this is a working HTML version where there are many extra attributes, protected comments, garbage tags etc.

You could execute editor.getData() when you copy from editor but this will give you text HTML (the same as switching to source mode).

comment:7 Changed 3 years ago by Eugene

Thank you for the comment! I thought that maybe CKEDITOR could run the same processing as it does when getData() is called, so that the copied HTML does not have those extra attributes you mentioned. I'm not sure though if CKEDITOR always (in all browsers) has access to clipboard to put preprocessed HTML to it, but I believe it does in some cases?

comment:8 Changed 3 years ago by Jakub Ś

I thought that maybe CKEDITOR could run the same processing as it does when getData() is called,

It doesn't auto do that but perhaps you could. I haven't tried it but you could listen to key event, get data there and try to change HTML:

editor.on( 'key', function( evt ) {
	var keyCode =;
		if (  keyCode == CKEDITOR.CTRL + 67 ) {// Ctrl+C
			//Change HTML here...
} /*, null, null, 10*/ ); // perhaps some priority adjustents to value below 10 will be needed

@e.arshinov I think I will discuss it with the team to get all point of views. In general text content is needed in 90% of cases. Users sometimes also copy data form and paste it into editor and in such cases data should not be cleaned.

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