From e0e4780c9dfb0b9dfab41dbb727370c8ff6340f1 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Fri, 20 Mar 2015 20:33:55 +0000 Subject: [PATCH] TinyMCE: when pasting an URL, check if the node it is pasted at is empty and remove any empty inline child elements. Fixes #31158. git-svn-id: https://develop.svn.wordpress.org/trunk@31856 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/tinymce/plugins/wpview/plugin.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js index d5178d62ac..359d7f8bac 100644 --- a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js @@ -173,13 +173,20 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { return; } - node = editor.selection.getNode(); + if ( ! event.load ) { + node = editor.selection.getNode(); - // When a url is pasted, only try to embed it when pasted in an empty paragrapgh. - if ( event.content.match( /^\s*(https?:\/\/[^\s"]+)\s*$/i ) && - ( node.nodeName !== 'P' || node.parentNode !== editor.getBody() || ! editor.dom.isEmpty( node ) ) ) { + if ( node && node !== editor.getBody() && /^\s*https?:\/\/\S+\s*$/i.test( event.content ) ) { + // When a url is pasted or inserted, only try to embed it when it is in an empty paragrapgh. + node = editor.dom.getParent( node, 'p' ); - return; + if ( node && /^[\s\uFEFF\u00A0]*$/.test( node.textContent || node.innerText ) ) { + // Make sure there are no empty inline elements in the

+ node.innerHTML = ''; + } else { + return; + } + } } event.content = wp.mce.views.setMarkers( event.content );