Ticket #1099 (closed defect: duplicate)

Opened 4 years ago

Last modified 2 years ago

wpautop filter may product invalid markup

Reported by: idanso Assigned to: 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 (2.2 kB) - added by idanso on 05/21/05 06:36:41.
formatting.php.diff (1.0 kB) - added by filosofo on 08/30/06 07:33:12.

Change History

03/13/05 06:23:15 changed by idanso

  • Patch set to No.

05/04/05 04:28:41 changed by bronski

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.

05/21/05 06:36:41 changed by idanso

  • attachment testcase.php added.

05/21/05 17:11:34 changed by Jon Leighton (Turnip)

  • cc set to turnip@turnipspatch.com.

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>

08/30/06 07:33:12 changed by filosofo

  • attachment formatting.php.diff added.

08/30/06 07:33:55 changed by filosofo

  • keywords set to bg|has-patch.
  • 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.

12/01/06 01:36:30 changed by matt

  • 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>

02/20/07 06:34:54 changed by rob1n

  • cc deleted.
  • keywords deleted.
  • status changed from new to closed.
  • resolution set to duplicate.

Dupe of #3669, which has since been fixed.

02/20/07 06:35:01 changed by rob1n

  • milestone deleted.