[wp-trac] [WordPress Trac] #49947: the_content can create potentially broken html

WordPress Trac noreply at wordpress.org
Sat Apr 18 13:44:00 UTC 2020


#49947: the_content can create potentially broken html
------------------------------+-----------------------------
 Reporter:  alekseizhuravlev  |      Owner:  (none)
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Post Formats      |    Version:  5.4
 Severity:  normal            |   Keywords:
  Focuses:                    |
------------------------------+-----------------------------
 filter 'the_content' by default uses wpautop function, which contains
 problem
 when original string contains '<p></p>' wpautop replaces it with '</p>',
 so resulting string will contain closing p tag without opening p tag
 after debugging i realised that line 579 in /wp-includes/formatting.php
 contains the following code:
 {{{#!php
 <?php
 $pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)!', '$1', $pee
 );
 }}}

 which is potentially the source of a problem. that code works only when
 $pee doesn't contain '<p></p>', previously removed on line 563 by the
 following:
 {{{#!php
 <?php
 $pee = preg_replace( '|<p>\s*</p>|', '', $pee );
 }}}
 but p's are just added by line 559, so we have '<p><p></p></p>' and code
 above will remove only one p, and the code at line 579 will break html.
 so i suggest to use something like this for temporary decision
 {{{#!php
 <?php
 while (preg_match('|<p>\s*</p>|', $pee)) {
         $pee = preg_replace( '|<p>\s*</p>|', '', $pee );
 }
 }}}
 on line 563

 sorry for poor formatting, that is my first report

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49947>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list