[wp-trac] [WordPress Trac] #26842: Contenteditable, multiple spaces, &nbsp, and U+00A0

WordPress Trac noreply at wordpress.org
Thu Mar 23 22:33:44 UTC 2017


#26842: Contenteditable, multiple spaces, &nbsp, and U+00A0
------------------------------+-----------------------------
 Reporter:  azaozz            |       Owner:
     Type:  defect (bug)      |      Status:  new
 Priority:  normal            |   Milestone:  Future Release
Component:  TinyMCE           |     Version:  4.7
 Severity:  normal            |  Resolution:
 Keywords:  needs-unit-tests  |     Focuses:
------------------------------+-----------------------------

Comment (by CK MacLeod):

 Replying to [comment:23 CK MacLeod]:

 Just wanted to correct some misinformation in my prior comment. The
 function that will remove the code from post content on save is the
 following (variations with wp_insert_post_data) also work:

 While this thread was still open, I just wanted to correct my prior
 answers. I've gone into more detail here -
 https://ckmacleod.com/2017/03/23/exterminating-non-breaking-space-bug/ -
 but, in short, the snippet that I gave previously just happens to work, in
 effect by coincidence, if you have Next Generation Gallery installed -
 very complicated. Also, the problem isn't "hexadecimal," though is on the
 level of character encoding.

 What will work to get rid of bad non-breaking spaces of the type being
 discussed here is the following function:


 {{{
 add_filter( 'content_save_pre', 'remove_buggy_nbsps', 99, 2 );

 function remove_buggy_nbsps( $content ) {

    return str_replace( '\xc2\xa0', ' ', $content);

 }
 }}}


 Because the problem relates to UTF-8 character code in the database. More
 Exterminating the Non-Breaking Space Bug[https://wp.me/p4h0Xw-gGR],
 including ways to deal with already-archived posts and to exclude certain
 types of post.

 I believe the code used on another thread (at
 [https://core.trac.wordpress.org/ticket/31157#comment:5] ) may also work,
 but I still have to test it:


 {{{
 tinymce.on('AddEditor', function(event) {

   var editor = event.editor;

   editor.on('getContent', function (e) {

     var content = editor.getContent({format: "raw", no_events: 1});
     e.content = content.replace(/ /ig, ' ');

   });

 });
 }}}
 The above actually relates to the peculiar feature of Next Generation
 Gallery plug-in (buried deep in its code) that served to enable the prior
 function - that uses
 {{{
  
 }}}
  instead of
 {{{
 \xc2\xa0
 }}}
 and worked!

 Long story. I just know that people like me looking for solutions often
 arrive at threads like this one looking for answers - and I didn't want to
 leave a bad one unaltered.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/26842#comment:24>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list