Make WordPress Core

Opened 19 years ago

Closed 17 years ago

Last modified 17 years ago

#1099 closed defect (bug) (duplicate)

wpautop filter may product invalid markup

Reported by: idanso's profile idanso Owned by:
Milestone: Priority: normal
Severity: minor Version: 2.1
Component: General Keywords:
Focuses: Cc:


The wpautop filter, enabled by default on Wordpress 1.5, produces not well formed XHTML in some cases.

One such case occurs when the input has a 'pee' block contained within a 'div' block, and there is a newline, followed by atext between the end of the 'pee' block and the end of the 'div' block.

In such a case, wpautop will open a 'pee' block at the start of the text block, but will not close it.

For example:

Will product:

Attachments (2)

testcase.php (2.2 KB) - added by idanso 19 years ago.
formatting.php.diff (1.0 KB) - added by filosofo 17 years ago.

Download all attachments as: .zip

Change History (9)

#1 @idanso
19 years ago

  • Patch set to No

#2 @bronski
19 years ago

This could be related to

It was once fixed with pre and code but is broken with code now.

19 years ago

#3 @Jon Leighton (Turnip)
19 years ago

  • Cc turnip@… added

Well, here's a patch (kinda). It might need some more elements, and probably needs a bit more testing, but it worked for me...

	$pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "\t<p>$1</p>\n", $pee); // make paragraphs, including one at the end 
+	$pee = preg_replace('!(<(?:div|address|form)[^>]*>)([^<]+)</p>!', "$1<p>$2</p>", $pee);
+	$pee = preg_replace('!<p>([^<]+)\s*?(</(?:div|address|form)[^>]*>)!', "<p>$1</p>$2", $pee);
	$pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace 

To prevent the invalid markup being produced, I found that at least two newlines were needed between the containing elements's tag (div, address etc.) and the text that needs to be peed. So this would be ok:


some words

some more words


But this wouldn't:

some words

some more words

#4 @filosofo
17 years ago

  • Keywords bg|has-patch added
  • Milestone set to 2.1
  • Version changed from 1.5.1 to 2.1

Jon Leighton's patch (which I've attached) works for me.

#5 @matt
17 years ago

  • Milestone changed from 2.1 to 2.2

The patch breaks when there is any markup in the string:

some words

some more <a href="">and a link</a> words

#6 @rob1n
17 years ago

  • Cc turnip@… removed
  • Keywords bg|has-patch removed
  • Resolution set to duplicate
  • Status changed from new to closed

Dupe of #3669, which has since been fixed.

#7 @rob1n
17 years ago

  • Milestone 2.2 deleted
Note: See TracTickets for help on using tickets.