Ticket #53 (closed defect (bug): fixed)
WordPress deletes some text when HTML tags incorrectly nested
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | General | Version: | 1.2 |
| Severity: | minor | Keywords: | |
| Cc: |
Description
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.
Example:
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
Change History
comment:1
anonymousbugger — 8 years ago
comment:2
coffee2code — 8 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:
<ul> <li>Won't close this item. <li>But will close this one.</li> </ul> <p>0123456789ABCDEFGH Note the LI wasn't closed.</p>
Here's what you'll wind up with:
<ul> <li>Won't close this item. <li>But will close this one.</li> </li></ul> <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
comment:3
coffee2code — 8 years ago
Of course, you'd actually use the '<' character instead of <
comment:4
anonymousbugger — 8 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?
comment:5
coffee2code — 8 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 </li> tags)
- closes unclosed known single-entity tags
- recognizes any properly-defined single-entity tag
- prevents insertion of non-sensical </> 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.
-Scott http://www.coffee2code.com
edited on: 08-16-04 14:16
edited on: 08-16-04 14:17
comment:6
anonymousbugger — 7 years ago
thanks a lot for the diff - seems to be working ok now
- Version set to 1.2
- Severity changed from major to minor
- Patch set to Yes
- Owner changed from anonymous to matt
- fixed_in_version set to 1.5
- Status changed from new to closed
- Resolution changed from 10 to 20
Applied patch, seems to be working.

