WordPress.org

Make WordPress Core

#49947 closed defect (bug) (duplicate)

the_content can create potentially broken html

Reported by: alekseizhuravlev Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.4
Component: Formatting Keywords:
Focuses: Cc:

Description

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
$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
$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
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

Change History (1)

#1 @SergeyBiryukov
15 months ago

  • Component changed from Post Formats to Formatting
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there, welcome to WordPress Trac!

Thanks for the report, we're already tracking this issue in #18136 and #27350.

Note: See TracTickets for help on using tickets.