Ticket #1099 (closed defect (bug): duplicate)

Opened 7 years ago

Last modified 5 years ago

wpautop filter may product invalid markup

Reported by: idanso Owned by: anonymous
Priority: normal Milestone:
Component: General Version: 2.1
Severity: minor Keywords:
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

testcase.php Download (2.2 KB) - added by idanso 7 years ago.
formatting.php.diff Download (1.0 KB) - added by filosofo 5 years ago.

Change History

  • Patch set to No

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.

idanso7 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>
  • Keywords bg|has-patch added
  • Version changed from 1.5.1 to 2.1
  • Milestone set to 2.1

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

comment:5   matt5 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>
  • Cc turnip@… removed
  • Keywords bg|has-patch removed
  • Status changed from new to closed
  • Resolution set to duplicate

Dupe of #3669, which has since been fixed.

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