Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#10851 closed defect (bug) (fixed)

TinyMCE occasionally leaves junk behind when copy and pasting

Reported by: Denis-de-Bernardy Owned by: azaozz
Milestone: 2.9 Priority: normal
Severity: normal Version: 2.8.4
Component: TinyMCE Keywords:
Focuses: Cc:


such as:

<div id="_mcePaste" style="overflow: hidden; position:
absolute; left: -10000px; top: 0px; width: 1px; height:
1px;">pasted code goes here</div>

Change History (6)

#1 @Denis-de-Bernardy
6 years ago

some code to fix it, in case there is any interest:

	 * fix_tinymce_paste()
	 * @param string $content
	 * @return string $content

	function fix_tinymce_paste($content) {
		if ( strpos($content, '_mcePaste') === false )
			return $content;
		$content = stripslashes($content);
		do {
			$old_content = $content;
			$content = preg_replace_callback("~(<div id=\"_mcePaste\".*?>)(.*?)(</div>)~is", 'fix_tinymce_paste_callback', $old_content);
		} while ( $content && $content != $old_content );
		global $wpdb;
		$content = $wpdb->escape($content);
		return $content;
	} # fix_tinymce_paste()
	 * fix_tinymce_paste_callback()
	 * @param array $match
	 * @return string $output
	function fix_tinymce_paste_callback($match) {
		$content = $match[2];
		if ( !$content || strpos(strtolower($content), '<div') === false )
			return '';
		$content .= $match[3];
		do {
			$old_content = $content;
			$content = preg_replace("~<div.*?>.*?</div>~is", '', $old_content);
		} while ( $content && $content != $old_content );
		return $match[1] . $content;
	} # fix_tinymce_paste_callback()

add_filter('content_save_pre', 'fix_tinymce_paste', 0);

#2 @azaozz
6 years ago

  • Keywords reporter-feedback added

This is a workaround in TinyMCE for (older) browsers that don't have the onpaste event. The div should be removed on cleanup, can you see if it still happens in current trunk (TinyMCE 3.2.7).

#3 @Denis-de-Bernardy
6 years ago

I've never experienced it, myself, so I wouldn't know how to reliably reproduce.

#4 follow-up: @hakre
6 years ago

I experienced something maybe simlar while testing the stuff for #10252 . I'm using the svn version and potential latest browsers (which is a misleading argument by azaozz imho anyway) and the stuff still sticks in. crap left befind. I did not care because I thought this is just how things are done these ways.... .

#5 in reply to: ↑ 4 @azaozz
6 years ago

Replying to hakre:

I experienced something maybe similar...

Does it still happen after svn up? Any way to consistently reproduce?

(which is a misleading argument ...

The 'onpaste' event is supported in IE, Safari and Chrome, nearly there in FF 3.5, not supported in FF 2 and Opera (not sure about Opera 10) and partially supported in FF 3.0. Other browsers based on the same engines may support it too.

#6 @azaozz
6 years ago

  • Keywords reporter-feedback removed
  • Resolution set to fixed
  • Status changed from new to closed

This should be fixed in the latest TinyMCE. Feel free to reopen with more details if it happens again.

Note: See TracTickets for help on using tickets.