From d51e1162981416933ae01a5eea8b4ca39c116d55 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sat, 20 Feb 2016 19:55:03 +0000 Subject: [PATCH] TinyMCE: fix the regex that removes spaces from empty paragraphs. Was causing problems when wpautop is disabled and there are many U+00A0 chars between the opening `

` and an inline tag. These chars are inserted by the browsers to maintain consecutive spaces typed by the users in contentEditable. Fixes #35890. git-svn-id: https://develop.svn.wordpress.org/trunk@36597 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/tinymce/plugins/wordpress/plugin.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js b/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js index 13ef3af059..7a811404cd 100644 --- a/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js @@ -117,7 +117,15 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { } // Remove spaces from empty paragraphs. - event.content = event.content.replace( /

(?: |\u00a0|\uFEFF|\s)+<\/p>/gi, '


' ); + // Avoid backtracking, can freeze the editor. See #35890. + // (This is also quite faster than using only one regex.) + event.content = event.content.replace( /

([^<>]+)<\/p>/gi, function( tag, text ) { + if ( /^( |\s|\u00a0|\ufeff)+$/i.test( text ) ) { + return '


'; + } + + return tag; + }); } });