[wp-trac] [WordPress Trac] #43387: wpautop() adds "</p>" where it should not

WordPress Trac noreply at wordpress.org
Thu Feb 22 15:20:31 UTC 2018


#43387: wpautop() adds "</p>" where it should not
--------------------------+-----------------------------
 Reporter:  1994rstefan   |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Formatting    |    Version:  3.0
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 There are a few cases where `wpautop()` creates invalid HTML code by
 inserting just a closing p tag. (Opening tag is missing)

 The problem exists with all block elements (defined inside wpautop
 function)

 {{{#!php
 $allblocks =
 '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
 }}}

 I have found two cases where this happens but there may be more.

 Minimal Examples:

 {{{#!php
 echo wpautop('<div>X<div></div></div>');
 echo PHP_EOL;
 echo wpautop('<div><div></div>
  </div>'); // note the space in front of the tag
 }}}


 Output:

 {{{
 <div>X</p>
 <div></div>
 </div>

 <div>
 <div></div>
 </p></div>
 }}}


 The problem is relevant because `wpautop` is used to filter
 `the_content()`.

 Examples what the user could insert inside the backend editor which
 results in this error:

 {{{
 <h1>Heading<div class="subheading">Subheading</div></h1>

 <div class="allign-center">
     <div class="image-wrap">
         <img src="about:blank" alt="example">
         <div class="image-description">just an example</div>
     </div>
 </div>
 }}}

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


More information about the wp-trac mailing list