Bug Tracker

Modify

Ticket #4074 (closed bug: fixed)

Opened 4 years ago

Last modified 4 years ago

.clone() doesn't respect ownerDocument

Reported by: friedcell Owned by: john
Priority: major Milestone: 1.3.2
Component: core Version: 1.3.1
Keywords: clone iframe Cc:
Blocking: Blocked by:

Description

If you clone an element from a foreign document (not the one you're executing code in), the cloned node will not have the same ownerDocument as the original element. It will instead be owned by the document where the execution happens.

elem.ownerDocument === document > false var clone = $(elem).clone(); clone.ownerDocument === elem.ownerDocument > false (should be true) clone.ownerDocument === document > true (should be false)

There is a simple fix to this - the code in clone() shouldn't use document.createElement but this.ownerDocument and the call to clear should use this for context (currently uses nothing).

Change History

comment:1 Changed 4 years ago by dmethvin

  • Keywords clone iframe added
  • Owner set to flesler

comment:2 Changed 4 years ago by john

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

This was fixed when the recent IE clone refactoring landed.

comment:3 Changed 4 years ago by doug

  • Status changed from closed to reopened
  • Resolution fixed deleted

Using this.ownerDocument for createElement is a partial fix. The call to clean() also needs the context.

That is,

return jQuery.clean([html.replace(/ jQuery\d+="(?:\d+|null)"/g, "").replace(/\s*/, "")], this.ownerDocument)[0];

I've seen the problem when using .wrap("<div></div>").

comment:4 Changed 4 years ago by dmethvin

  • Owner changed from flesler to john
  • Status changed from reopened to new

I think that was mentioned on one of the tickets for this issue but it got lost. Thanks!

comment:5 Changed 4 years ago by brandon

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

fixed in r6280

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.