Bug Tracker

Opened 14 years ago

Closed 12 years ago

#3295 closed bug (invalid)

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 (332 bytes) - added by dmethvin 13 years ago.
Test case for #3295

Download all attachments as: .zip

Change History (4)

comment:1 Changed 14 years ago by flesler

Cc: antonio.collins flesler added
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 13 years ago by dmethvin

Attachment: jqtest.htm added

Test case for #3295

comment:2 Changed 13 years ago by dmethvin

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.

comment:3 Changed 12 years ago by dmethvin

Resolution: invalid
Status: newclosed

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

Note: See TracTickets for help on using tickets.