Make WordPress Core

Changeset 31817


Ignore:
Timestamp:
03/18/2015 08:25:09 PM (9 years ago)
Author:
azaozz
Message:

TinyMCE: strip tags from pasted URLs before testing if they are embeddable.
Props siobhan, iseulde. Fixes #31158.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/tinymce/plugins/wpview/plugin.js

    r31732 r31817  
    168168    // view wrappers.
    169169    editor.on( 'BeforeSetContent', function( event ) {
    170         var node;
    171 
    172         if ( ! event.content ) {
     170        var pastedStr = event.content,
     171            trim = tinymce.trim,
     172            node;
     173
     174        if ( ! pastedStr ) {
    173175            return;
    174176        }
     
    180182        node = editor.selection.getNode();
    181183
     184        pastedStr = pastedStr.replace( /<[^>]+>/g, '' );
     185        pastedStr = trim( pastedStr );
     186
    182187        // When a url is pasted, only try to embed it when pasted in an empty paragrapgh.
    183         if ( event.content.match( /^\s*(https?:\/\/[^\s"]+)\s*$/i ) &&
    184             ( node.nodeName !== 'P' || node.parentNode !== editor.getBody() || ! editor.dom.isEmpty( node ) ) ) {
    185             return;
     188        if ( /^https?:\/\/\S+$/i.test( pastedStr ) ) {
     189            event.content = pastedStr;
     190
     191            node = editor.dom.getParent( node, function( node ) {
     192                if ( node.parentNode === editor.getBody() ) {
     193                    return node;
     194                }
     195            } );
     196
     197            if ( node.nodeName !== 'P' || trim( node.textContent ) || trim( node.innerText ) ) {
     198                return;
     199            }
    186200        }
    187201
Note: See TracChangeset for help on using the changeset viewer.