Bug Tracker

Modify

Ticket #3295 (closed bug: invalid)

Opened 5 years ago

Last modified 3 years ago

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
Blocking: Blocked by:

Description

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){
         return
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

jqtest.htm Download (332 bytes) - added by dmethvin 4 years ago.
Test case for #3295

Change History

comment:1 Changed 5 years ago by flesler

  • Cc antonio.collins, flesler added
  • need changed from Review to Test 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 4 years ago by dmethvin

Test case for #3295

comment:2 Changed 4 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 3 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.