Skip to main content

Bug Tracker

Side navigation

#3295 closed bug (invalid)

Opened August 26, 2008 09:05PM UTC

Closed June 20, 2010 07:17PM UTC

jQuery 1.2.X's .clean() mangles namespaced elements

Reported by: antonio.collins Owned by:
Priority: major Milestone: 1.3
Component: core Version: 1.2.6
Keywords: Cc: antonio.collins, flesler
Blocked by: Blocking:

The .clean() method tries to replace empty elements defined as <elem /> with <elem></elem>. Here's the code from .clean():

   // Convert html string into DOM nodes
   if ( typeof elem == "string" ) {
      // Fix "XHTML"-style tags in all browsers
      elem = elem.replace(/(<(\\w+)[^>]*?)\\/>/g, function(all, front, tag){
tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
            all :
            front + "></" + tag + ">";

If the element is namespaced like this:

<data:person name="john doe" id="123" />

the manufactured closing tag is incorrect and will cause some DOM injection methods to fail:

<data:person name="john doe" id="123" ></data>

Changing the regular expression's (\\w+) to ([A-Za-z0-9_:]+) fixes the problem.

Attachments (1)
  • jqtest.htm (0.3 KB) - added by dmethvin December 16, 2008 06:21PM UTC.

    Test case for #3295

Change History (3)

Changed August 26, 2008 09:27PM UTC by flesler comment:1

cc: → antonio.collins, flesler
need: ReviewTest Case

All 3 cases work well for me on FF2, the element is created successfully:

$('<data:person name="john doe" id="123" />')
$('<data:person name="john doe" id="123">')
$('<data:person name="john doe" id="123"></data:person>')

Could you provide a test case ? a minimalistic html file with the requires html and js to reproduce the problem. Specifying failing browser/OS as well.

Changed December 16, 2008 06:21PM UTC by dmethvin comment:2

I see the problem in IE7. FF3, Chrome 1.0, Safari 3.2.1, and Opera 9.63 work properly. The closing tag coming out of the code quoted above is incorrect, so I think the HTML parser must be fixing it for all but IE.

Test case attached.

Changed June 20, 2010 07:17PM UTC by dmethvin comment:3

resolution: → invalid
status: newclosed

Hey, waitaminit. This is XML and not HTML. jQuery doesn't parse XML.