WordPress.org

Make WordPress Core

Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#1099 closed defect (bug) (duplicate)

wpautop filter may product invalid markup

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

Description

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:
<div>
<p>Hello</p>
World</div>

Will product:
<div>
<p>Hello</p>
<p>World</div>

Attachments (2)

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

Download all attachments as: .zip

Change History (9)

#1 @idanso
12 years ago

  • Patch set to No

#2 @bronski
12 years ago

This could be related to http://mosquito.wordpress.org/view.php?id=488

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

@idanso
12 years ago

#3 @Jon Leighton (Turnip)
12 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:

<div>

some words

some more words

</div>

But this wouldn't:

<div>
some words

some more words
</div>

#4 @filosofo
11 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
11 years ago

  • Milestone changed from 2.1 to 2.2

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

<div>
some words

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

#6 @rob1n
11 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
11 years ago

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