Skip to main content

Bug Tracker

Side navigation

#2811 closed bug (fixed)

Opened May 06, 2008 11:31PM UTC

Closed May 08, 2008 05:11PM UTC

2 bugs on jQuery.fn.add

Reported by: flesler Owned by: flesler
Priority: major Milestone: 1.2.4
Component: core Version: 1.2.3
Keywords: add duplicated unique window form Cc:
Blocked by: Blocking:
Description

As mentioned here, $.fn.add is not calling $.unique, thus elements can get duplicated.

Also, the array-like detection is very naive, and will fail when receiving ~~a form~~, or the window if iframes are included.

That's why I change it so that it uses makeArray, which does smarter sniffing on array-like.

This also makes the code shorter.

Attachments (2)
  • add.diff (0.7 KB) - added by flesler May 07, 2008 12:19AM UTC.
  • testrunner-add.diff (1.1 KB) - added by flesler May 07, 2008 12:47AM UTC.

    Tests that can now pass

Change History (6)

Changed May 07, 2008 12:18AM UTC by flesler comment:1

status: newassigned

UPDATE:

I just got into the scariest IE quirk.

Just realized that form == form.elements. They're literally the same, can't differentiate them.

I decided (to keep this working as it was) that $(form) will consider it a form, but $.makeArray(form) will generate an array of elements, this is the behavior of $.fn.add.

In short, $.fn.add does a naive check, will mess up with $().add(window) and any other thing with length.

Changed May 07, 2008 12:49AM UTC by flesler comment:2

Noticed that one test of .html() fails on IE with this patch, because the created element gets the expando, so the resulting .html() includes it and is different than expected.

This shouldn't be relevant.

In conclusion, do we want to call .unique() inside .add() ??

Changed May 07, 2008 12:54AM UTC by flesler comment:3

description: As mentioned [http://groups.google.com/group/jquery-en/browse_thread/thread/9f4e76ad29237065/abcfb4f702f0f32c here], $.fn.add is not calling $.unique, thus elements can get duplicated. \ \ Also, the array-like detection is very naive, and will fail when receiving a form, or the window if iframes are included. \ \ That's why I change it so that it uses makeArray, which does smarter sniffing on array-like. \ \ This also makes the code shorter.As mentioned [http://groups.google.com/group/jquery-en/browse_thread/thread/9f4e76ad29237065/abcfb4f702f0f32c here], $.fn.add is not calling $.unique, thus elements can get duplicated. \ \ Also, the array-like detection is very naive, and will fail when receiving ~~a form~~, or the window if iframes are included. \ \ That's why I change it so that it uses makeArray, which does smarter sniffing on array-like. \ \ This also makes the code shorter.

Changed May 07, 2008 01:34AM UTC by scott.gonzal comment:4

This change looks good to me. makeArray should be used wherever possible and the added call to unique seems like expected behavior.

Changed May 07, 2008 10:08PM UTC by joern comment:5

There is nothing fun as the form element in IE.

Agreed with Scott!

Changed May 08, 2008 05:11PM UTC by flesler comment:6

resolution: → fixed
status: assignedclosed

Applied at [5503] and extra tests at [5504].