WordPress.org

Make WordPress Core

Opened 5 months ago

Last modified 5 months ago

#43100 new defect (bug)

Unexpected results from wpautop

Reported by: pross Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: trunk
Component: General Keywords:
Focuses: Cc:

Description

An empty paragraph will result in invalid HTML

To reproduce using default theme add echo wpautop( '<p></p>' ); into a template file.

Expected result <p></p>

Actual result </p>

Change History (3)

#1 @justinbusa
5 months ago

It looks like this happens in reverse for paragraph tags that have a style attribute. For example, this...

echo wpautop( '<p style="text-align:center;"></p>' );

will output... <p style="text-align:center;"> with no closing tag.

#2 @pross
5 months ago

Tested the bug as far back as WP 2.8, couldn't get anything earlier working in MAMP.

#3 @wiselyfoolish
5 months ago

Yup. This affects empty paragraphs only.

Current workaround solution is to strip empty paragraph tags from the text before running it through wpautop()

Example:

<?php
$text = '<p>First paragraph</p><p></p><p>Second Actual Paragraph</p>';
$text = preg_replace('@<p.*?></p>@', '', $text);
$text = wpautop($text);
?>
Last edited 5 months ago by wiselyfoolish (previous) (diff)
Note: See TracTickets for help on using tickets.