Make WordPress Core

Opened 12 years ago

Closed 5 years ago

#20444 closed defect (bug) (duplicate)

wpautop acts on a single line of text

Reported by: niallkennedy's profile niallkennedy Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Formatting Keywords: wpautop has-patch needs-refresh
Focuses: Cc:


HTML markup on a single line wrapped in a block element is interpreted and changed by wpautop. The wpautop function is described as replacing "double line-breaks with paragraph elements" which led me to expect the single line would not become many lines.

echo wpautop( '<div><p>Hello world</p><span>WordPress</span></div>' );
<p>Hello world</p>

Extra <p> before the <span>.

I expected wpautop would find no newlines and return the original string.

The same string placed inside a HTML5 or XHTML 1 Strict document <body> is parsed as valid by W3C Validator.

Plugins acting on the_content with a priority less than 10 may have their single-line markup reinterpreted by wpautop.

Attachments (3)

test-wpautop.php (225 bytes) - added by niallkennedy 12 years ago.
wp-load and call wpautop with a single line div
Autop-20444.diff (652 bytes) - added by jond 10 years ago.
Autop.php unit test coverage for #20444
Autop-20444-fixed.diff (643 bytes) - added by jond 10 years ago.
Updated expected results

Download all attachments as: .zip

Change History (13)

12 years ago

wp-load and call wpautop with a single line div

#1 @MarcusPope
12 years ago

Another (w3c valid fragment) variation that will fail is:


which results in:

<p>asdfasdfasdf<br/>asdfasdfasdf<br />


It's missing the closing p tag after <br />. Changing the first preg_replace|$allblocks line in formatting.php's wpautop function to replace matches with "\n\n$1" (instead of "\n$1") will fix the above, but creates problems for the test case attached to test-wpautop.php.




Though I'm guessing this ticket will be closed invalid as #7937 was. (sigh)

#3 @greenshady
12 years ago

  • Cc justin@… added

#4 @mdbitz
11 years ago

Hi, the p tag is considered a blocking element. In this case the output from wpautop should be:

<p>Hello world</p>

I'm in the process of writing a comprehensive set of unit tests on the wpautop function to verify its current functionality and allow proper regression testing as new enhancements are requested. I've added the above as a test case to confirm that the second p tag is properly closed.

It might be another week till it gets put up for review as there are a good amount of tickets to go through.

#5 @nacin
10 years ago

  • Keywords wpautop added

#6 @nacin
10 years ago

  • Keywords needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release

mdbitz's ticket with tests ended up being #25856.

Fine with trying to establish a fix for this. Let's make sure we have strong test coverage though.

10 years ago

Autop.php unit test coverage for #20444

#7 @jond
10 years ago

Submitted unit test for unbroken lines based on the report by @niallkennedy

10 years ago

Updated expected results

#8 @jond
10 years ago

  • Keywords has-patch added; needs-unit-tests removed

This issue has unit tests and a patch is available as part of the comprehensive patch on related issue #27350.

#9 @chriscct7
9 years ago

  • Keywords needs-refresh added

#10 @pento
5 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #27350.

Note: See TracTickets for help on using tickets.