TinyMCE: strip tags from pasted URLs before testing if they are embeddable.
Props siobhan, iseulde. Fixes #31158. git-svn-id: https://develop.svn.wordpress.org/trunk@31817 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
f288ec0581
commit
25a5f07d51
|
@ -167,9 +167,11 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||||
// matching view patterns, and transform the matches into
|
// matching view patterns, and transform the matches into
|
||||||
// view wrappers.
|
// view wrappers.
|
||||||
editor.on( 'BeforeSetContent', function( event ) {
|
editor.on( 'BeforeSetContent', function( event ) {
|
||||||
var node;
|
var pastedStr = event.content,
|
||||||
|
trim = tinymce.trim,
|
||||||
|
node;
|
||||||
|
|
||||||
if ( ! event.content ) {
|
if ( ! pastedStr ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,10 +181,22 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||||
|
|
||||||
node = editor.selection.getNode();
|
node = editor.selection.getNode();
|
||||||
|
|
||||||
|
pastedStr = pastedStr.replace( /<[^>]+>/g, '' );
|
||||||
|
pastedStr = trim( pastedStr );
|
||||||
|
|
||||||
// When a url is pasted, only try to embed it when pasted in an empty paragrapgh.
|
// 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 ) &&
|
if ( /^https?:\/\/\S+$/i.test( pastedStr ) ) {
|
||||||
( node.nodeName !== 'P' || node.parentNode !== editor.getBody() || ! editor.dom.isEmpty( node ) ) ) {
|
event.content = pastedStr;
|
||||||
return;
|
|
||||||
|
node = editor.dom.getParent( node, function( node ) {
|
||||||
|
if ( node.parentNode === editor.getBody() ) {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
if ( node.nodeName !== 'P' || trim( node.textContent ) || trim( node.innerText ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
event.content = wp.mce.views.setMarkers( event.content );
|
event.content = wp.mce.views.setMarkers( event.content );
|
||||||
|
|
Loading…
Reference in New Issue