πŸ’₯ TRENDING: Ticket/ - Collection

Opened 19 years ago

Closed 3 years ago

#3833 closed defect (bug) (worksforme)

Extra </p> inside blockquote

Reported by: audwan's profile audwan Owned by: archibald-leaurees's profile Archibald Leaurees
Milestone: Priority: normal
Severity: normal Version: 2.7
Component: Formatting Keywords: wpautop needs-refresh close
Focuses: Cc:

Description (last modified by foolswisdom)

When using blockquote </p> is inserted directly in front of </blockquote>, making the code invalid XHTML.

Example:

<blockquote>This is a blockquote</blockquote>

Gives the following result:

<blockquote>This is a blockquote</p></blockquote>

Seems like ​this forum thread adresses the same issue in the support forum.

Attachments (6)

wpautopdebug.php​ (4.5 KB) - added by Archibald Leaurees 17 years ago.
Debuggin wpautop function php file
3833.diff​ (813 bytes) - added by Denis-de-Bernardy 17 years ago.
add an extra \n before block elts
3833.2.diff​ (988 bytes) - added by Denis-de-Bernardy 17 years ago.
better patch, that fixes #6041 as well
3833.3.diff​ (2.1 KB) - added by Denis-de-Bernardy 17 years ago.
fix <li>\n<p>foo bar</p>\n</li>
3833.4.diff​ (1.2 KB) - added by jorbin 11 years ago.
Originally created by MikeHansenMe on #30142
3833.5.diff​ (1.2 KB) - added by jared_smith 10 years ago.
Updated patch with unit tests

Download all attachments as: .zip

Change History (45)

#1 @foolswisdom
19 years ago

  • Milestone changed from 2.1.3 to 2.2

#2 @rob1n
19 years ago

  • Milestone 2.2 deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Using <blockquote> inside <li> is invalid. Use <q> instead.

For me, <blockquote>Hello, world. Wonder what this will do.</blockquote> puts <p>...</p> inside the <blockquote> fine.

This is with r5142. Closing as worksforme.

#3 @Goingthewongway
18 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened
  • Version changed from 2.1 to 2.3.1

On version 2.3.1 this is still an issue.

For example, a post with only <blockquote>some quote</blockquote> will result in <blockquote>some quote</p></blockquote>, which is invalid XHTML.

This seems to me to be a result of:

  1. formatting.php:78 $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
  2. not having/not adding an opening "<p>" tag at the beginning of the post (even though it does get added for other all-text entries)

#4 @foolswisdom
18 years ago

  • Description modified (diff)
  • Keywords wpautop autop added
  • Priority changed from low to normal

ENV: WP trunk r6301

Confirmed bug exists as described.

The bug won't reproduce if there are no blank lines before the blockquotes, or if there is a paragraph before the blockquote. That likely explains it working for rob1n .

Repro having a block quote by the only text, inserted using visual editor.

Removed that part about blockquote in a list from description.

#5 @foolswisdom
18 years ago

  • Milestone set to 2.4

@Archibald Leaurees
17 years ago

Debuggin wpautop function php file

#6 @Archibald Leaurees
17 years ago

  • Cc Archibald Leaurees added
  • Component changed from Administration to Validation
  • Owner changed from anonymous to Archibald Leaurees
  • Status changed from reopened to new
  • Version changed from 2.3.1 to 2.7

This bug is still there.
When wpautop deals with that content :

    text before
    <div class="whatever">
      <blockquote>
        text inside the blockquote tag
      </blockquote>
      Some text inside the div embedding the blockquote and after the closing blockquote tag
    </div>

wpautop returns the following output :

<p>    text before</p>
<div class="whatever">
<blockquote><p>
        text inside the blockquote tag
      </p></blockquote>
<p>      Some text inside the div embedding the blockquote and after the closing blockquote tag
    </p></div>

Everything is ok. The output of wpautop is just like we want it to be.
But when we try the following input :

    text before    <div class="whatever">
      <blockquote>
        text inside the blockquote tag
      </blockquote>
      Some text inside the div embedding the blockquote and after the closing blockquote tag
    </div>

wpautop returns :

<p>    text before
<div class="whatever">
<blockquote><p>
        text inside the blockquote tag
      </p></blockquote>
<p>      Some text inside the div embedding the blockquote and after the closing blockquote tag
    </p></div>

Obviously that's not a valid HTML. There's an openning 'p' tag just at the beginning, which one won't be closed.

We can reproduce that bug also using the following HTML code sample :

    text before    <div class="whatever"><blockquote>
        text inside the blockquote tag
      </blockquote>
      Some text inside the div embedding the blockquote and after the closing blockquote tag
    </div>

After passing that content to wpautop, we have, as output, the following content :

<p>    text before
<div class="whatever">
<blockquote>
        text inside the blockquote tag
      </p></blockquote>
<p>      Some text inside the div embedding the blockquote and after the closing blockquote tag
    </p></div>

As you can see there's some orphan tags. The openning p-tag before the beginning text and a closing p-tag just before the closing blockquote-tag.

There's other examples. But the two given are clear enough.

I've spent some hours looking for a solution or a patch. Helping is better that complaining. I've extracted the function, put it in a separated file and give it the real output of 'get_shortcode_regex()', because wpautopo uses it. you can have a look on the page I used here ​http://www.flegme.fr/wpautopdebug.php. And here's the same page with my bug fix applied ​http://www.flegme.fr/wpautopdebugafter.php (the php deugging file is attached as wpautopdebug.php)

So the solution is rather simple. In the wpautop php code at line 37,38 you've got :

	$pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
	$pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);

I've noticed that those two lines add newlines '\n' before and after some special tags (including the 'div' tag and the 'blockquote' tag). But the first regular expression adds one '\n' only where the second one adds two ones.

When I modify the code that it inserts two newlines before and after the special tags, the bug disapears.

So those two lines become :

	$pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\n$1", $pee);
	$pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);

Maybe i've missed something and my solution is not the good one... But that worked fine for me.

Regards

Archibald Leaurees

#7 @Denis-de-Bernardy
17 years ago

  • Component changed from Validation to Formatting

#9 @Denis-de-Bernardy
17 years ago

in 11256:

<blockquote>some quote</blockquote>

works fine

    text before
    <div class="whatever">
      <blockquote>
        text inside the blockquote tag
      </blockquote>
      Some text inside the div embedding the blockquote and after the closing blockquote tag
    </div>

clunky but works too

    text before    <div class="whatever">
      <blockquote>
        text inside the blockquote tag
      </blockquote>
      Some text inside the div embedding the blockquote and after the closing blockquote tag
    </div>

fails

    text before    <div class="whatever"><blockquote>
        text inside the blockquote tag
      </blockquote>
      Some text inside the div embedding the blockquote and after the closing blockquote tag
    </div>

fails

and the patch fixes everything indeed.

@Denis-de-Bernardy
17 years ago

add an extra \n before block elts

#10 @Denis-de-Bernardy
17 years ago

  • Keywords has-patch tested commit added; blockquote invalid list paragraph tags wpautop autop removed
  • Milestone changed from 2.9 to 2.8

@Denis-de-Bernardy
17 years ago

better patch, that fixes #6041 as well

#11 @Denis-de-Bernardy
17 years ago

just closed #6401 as dup. second patch fixes this:

<dd>paragraph 1

paragraph 2

paragraph 3</dd> 

#12 @Denis-de-Bernardy
17 years ago

second patch also fixes #7988:

<div><a href="xx"> <img src="yy" /> </a> <p>text</p> </div>