[wp-trac] [WordPress Trac] #1597: balanceTags() doesn't filter self-closing tags which shouldn't be self-closed

WordPress Trac wp-trac at lists.automattic.com
Thu Oct 14 19:12:11 UTC 2010


#1597: balanceTags() doesn't filter self-closing tags which shouldn't be self-
closed
--------------------------+-------------------------------------------------
 Reporter:  frenzie       |        Owner:  rob1n         
     Type:  defect (bug)  |       Status:  reopened      
 Priority:  normal        |    Milestone:  Future Release
Component:  Formatting    |      Version:  1.5.2         
 Severity:  minor         |   Resolution:                
 Keywords:  has-patch     |  
--------------------------+-------------------------------------------------
Changes (by coffee2code):

  * keywords:  needs-refresh => has-patch


Comment:

 By way of some research for self-closing tags:

 For XHTML 1.0, see
 http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_XHTML-1.0-Transitional and
 search for "EMPTY>".
 {{{
         area, base, basefont, br, col, frame, hr, img, input, isindex
 (deprecated), link, meta, param
 }}}

 For HTML5, see http://dev.w3.org/html5/html-author/ and search for "End
 tag: empty".
 {{{
         area, base, br, col, command, embed, hr, img, input, link, meta,
 param, source
 }}}

 For HTML4.01, see http://www.w3.org/TR/REC-html40/sgml/dtd.html and search
 for "EMPTY"
 {{{
         area, base, br, col, frame, hr, img, input, link, meta, param
 }}}

 Currently we only support/recognize:
 {{{
         br, hr, img, input
 }}}

 The included patch now supports the superset of all above-mentioned tags:
 {{{
         area, base, basefont, br, col, command, embed, frame, hr, img,
 input, isindex, link, meta, param, source
 }}}

 Here's a poor man's unit test.  Sample post content:
 {{{
 Here are some samples:

 A <strong class="something" style="text-align:bold;" /> phrase which
 shouldn't become bold.

 An <em/> unspaced invalid single-tag, which shouldn't italicize anything.

 A known tag <br> that didn't close itself.  Even with <br class="break">
 attributes.  Both cases should see line breaks.

 A known tag <hr/> and with space <hr /> and with attributes: <hr
 class="heavy"/> or <hr class="light" />. Spacing makes no difference here.
 }}}

 Without the patch, and with tag balancing enabled, the above content is
 considered perfectly balanced and is unmodified (despite invalid self-
 closing tags).  Most browsers will interpret the 'strong' and 'em' as
 being open tags, and without any matching closing tags, visual havoc is
 wrecked on the rest of the page on the front-end, in addition to not
 validating.

 After patching, however, the content is modified to:

 {{{
 Here are some samples:

 A <strong class="something" style="text-align:bold;" ></strong> phrase
 which shouldn't become bold.

 An <em ></em> unspaced invalid single-tag, which shouldn't italicize
 anything.

 A known tag <br /> that didn't close itself.  Even with <br
 class="break"/> attributes.  Both cases should see line breaks.

 A known tag <hr /> and with space <hr /> and with attributes: <hr
 class="heavy"/> or <hr class="light" />. Spacing makes no difference here.
 }}}

 '''''Of particular note is that `force_balance_tags()` is enabled by
 default for visitor comments, meaning for some themes (including Twenty
 Ten) in most browsers (at least Safari 4.1, FF 3.6+), a commenter could
 easily make a comment that would screw up the appearance of anything that
 came after it.'''''


 ----

 I know mucking with `force_balance_tags()` can cause some unease, but as
 some background on the matter: I was responsible for a number of fix-ups
 to the function back in 2004 (for #53, which got committed in [2057]).
 This includes the implementation of the existing self-closing tag support.
 I don't think much has been done to the function since then.

 That said, testers welcome!

 (As an aside: I could have sworn I provided a ticket + patch at a later
 time to more thoroughly cover other self-closing tags, but it never got
 committed and I never pursued it -- can't find it though.  Regardless,
 this is more thorough and current.)

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/1597#comment:14>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list