Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 3 years ago

#53 closed defect (bug) (fixed)

WordPress deletes some text when HTML tags incorrectly nested

Reported by: anonymousbugger Owned by: matt
Milestone: Priority: normal
Severity: minor Version: 1.2
Component: General Keywords:
Focuses: Cc:


If I use HTML in my post, it has to be correctly nested. If I accidentally forget to close a tag, Wordpress closes that tag for me, but a few characters that were entered after the tag are deleted.


I have a page of lists. Each one starts with a paragraph (with opening and closing p tags). After each one is an unordered list (ul) with many li's. If I leave one li open, it gets closed, but a few characters afterwards are deleted.

Attachments (1)

0000053-balancetags-patch2.diff (2.6 KB) - added by anonymousbugger 15 years ago.

Download all attachments as: .zip

Change History (10)

#2 @coffee2code
16 years ago

I've encountered a fair number of WordPress formatting bugaboos. If someone wishes to easily reproduce this particular bug, here is a sample. In the entry body of a post, input this:

<li>Won't close this item.
<li>But will close this one.</li>
<p>0123456789ABCDEFGH Note the LI wasn't closed.</p>

Here's what you'll wind up with:

<li>Won't close this item.
<li>But will close this one.</li>
<p>ABCDEFGH Note the LI wasn't closed.</p>

WordPress just ate 10 characters (the numbers 0 - 9). From what I've seen, it's always 10 characters that it eats.

The other formatting bugs I came across can be found here, if interested:
<a href="http://www.coffee2code.com/archives/2004/06/29/wordpress-formatting-bugs/">http://www.coffee2code.com/archives/2004/06/29/wordpress-formatting-bugs/</a>

edited on: 06-30-04 19:21

#3 @coffee2code
16 years ago

Of course, you'd actually use the '<' character instead of &lt;

#4 @anonymousbugger
16 years ago

yup I brought this up in the forums before they added the bug tracking feature, but got no reply. any chance that a wordpress developer may pass this report and have a look?

#5 @coffee2code
16 years ago

I've attached the file balancetags-patch2.diff to this bug report. The diff contains modifications to the function balanceTags() -- found in wp-includes/functions-formatting.php -- that is responsible for this bug. In addition to eating user text, the original balanceTags() function would in certain circumstances not do its job of balancing tags or would do so incorrectly. I've posted an analysis ( http://www.coffee2code.com/archives/2004/08/02/examining-balancetags ) of the various problems with the function (not the same as the link I provided in my previous comment to this bug). I've also posted an explanation ( http://www.coffee2code.com/archives/2004/08/03/fixing-balancetags ) of the changes I made to the code, as well as a copy of the new function in its entirety.

The fixes to the function aren't really all that numerous, and have been tested by at least one other person on the wp-hackers list. The fixes:

  • prevent user text from ever being deleted
  • properly balances tags immediately nested within themself (particularly list elements with missing &lt;/li> tags)
  • closes unclosed known single-entity tags
  • recognizes any properly-defined single-entity tag
  • prevents insertion of non-sensical &lt;/> tag
  • balances tags in the situation where the original wouldn't

At the very least the fixed function definitely improves upon the original and can hold down the fort until a more thorough XHTML-validator/fixer-upper comes along.


edited on: 08-16-04 14:16

edited on: 08-16-04 14:17

#6 @anonymousbugger
16 years ago

thanks a lot for the diff - seems to be working ok now

#7 @2fargon
16 years ago

  • Patch set to Yes
  • Severity changed from major to minor
  • Version set to 1.2

#8 @matt
16 years ago

  • fixed_in_version set to 1.5
  • Owner changed from anonymous to matt
  • Resolution changed from 10 to 20
  • Status changed from new to closed

Applied patch, seems to be working.

This ticket was mentioned in Slack in #core by westonruter. View the logs.

3 years ago

Note: See TracTickets for help on using tickets.