Make WordPress Core

Opened 18 years ago

Closed 18 years ago

#3238 closed defect (bug) (fixed)

Bug Fix in wpautop for Dangling Paragraph Tag in Wordpress Comments

Reported by: ghidra99's profile Ghidra99 Owned by:
Milestone: 2.1 Priority: normal
Severity: normal Version: 2.0.4
Component: General Keywords: wpautop autop dangling paragraph format formatting comments comment has-patch needs-testing maint-candidate
Focuses: Cc:

Description

I've figured out the wpautop bug that creates the hanging </p> tag in Wordpress comments.

If you go to functions-formatting.php in Wordpress 2.0.4, located at "wp-includes/functions-formatting.php" you'll see that line 65 reads:

$pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end

This creates:

<p>Hello, my name is Hal.</p>
<p>You've found my blog.
</p>

The third \n (newline) is what is creating the problem. If you take it out, your final </p> tag will appear inline with your final sentence. It should read:

$pee = preg_replace('/\n?(.+?)(?:\n\s*|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end

The text will now appear as:

<p>Hello, my name is Hal.</p>
<p>You've found my blog.</p>

For added styling, you can aline the final <p> with the rest of your markup by adding three (or however many you need) tabs (\t) after the final newline (\n) in line 65. It should look like this:

$pee = preg_replace('/\n?(.+?)(?:\n\s*|\z)/s', "<p>$1</p>\n\t\t\t", $pee); // make paragraphs, including one at the end

IMO, the styling should be added so that the user receives well-formed HTML and XTHML in their source.

Attachments (2)

3238_20.diff (1.2 KB) - added by Nazgul 18 years ago.
3238_trunk.diff (1.2 KB) - added by Nazgul 18 years ago.

Download all attachments as: .zip

Change History (7)

#1 @foolswisdom
18 years ago

Ghidra99, Can you add your fix as a patch? It is so much easier to read. Also, please consider commenting whether the same issue exists on trunk and a patch for it.

#2 @Ghidra99
18 years ago

foolswisdom, I just took a look at the trunk code for formatting.php and it includes the bug as well.

It's at line 72:

$pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end

The updated code should read:

$pee = preg_replace('/\n?(.+?)(?:\n\s*|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end

Unfortunately, I'm not sure how to create patch files so this would be easily readable.

@Nazgul
18 years ago

@Nazgul
18 years ago

#3 @Nazgul
18 years ago

  • Keywords has-patch needs-testing added

Created and attached (untested) patches based on the given code for 2.0 branch and trunk.

#4 @foolswisdom
18 years ago

  • Keywords maint-candidate added
  • Milestone changed from 2.0.5 to 2.1

Updated milestone to 2.1 as 2.0.5 is already release candidate and will soon be released.

#5 @matt
18 years ago

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

(In [4562]) Small cleanup to autop, fixes #3238

Note: See TracTickets for help on using tickets.