WordPress.org

Make WordPress Core

Opened 21 months ago

Last modified 9 months ago

#43100 new defect (bug)

Unexpected results from wpautop

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

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 (4)

#1 @justinbusa
21 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
21 months ago

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

#3 @wiselyfoolish
21 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 21 months ago by wiselyfoolish (previous) (diff)

#4 @pento
9 months ago

  • Version trunk deleted
Note: See TracTickets for help on using tickets.