jQuery: The Write Less, Do More JavaScript Library

Ticket #2811 (closed bug: fixed)

Opened 1 week ago

Last modified 5 days ago

2 bugs on jQuery.fn.add

Reported by: flesler Assigned to: flesler
Type: bug Priority: major
Milestone: 1.2.4 Component: core
Version: 1.2.3 Keywords: add duplicated unique window form
Cc: Needs: Patch

Description (last modified by flesler) (diff)

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

add.diff (0.7 kB) - added by flesler 1 week ago.
testrunner-add.diff (1.1 kB) - added by flesler 1 week ago.
Tests that can now pass

Change History

Changed 1 week ago by flesler

  • status changed from new to assigned

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 1 week ago by flesler

Changed 1 week ago by flesler

Tests that can now pass

Changed 1 week ago by flesler

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 1 week ago by flesler

  • description changed from 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. to 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 1 week ago by scott.gonzalez

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

Changed 5 days ago by joern

There is nothing fun as the form element in IE.

Agreed with Scott!

Changed 5 days ago by flesler

  • status changed from assigned to closed
  • resolution set to fixed

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

Note: See TracTickets for help on using tickets.