Bug Tracker

Modify

Ticket #3102 (closed enhancement: fixed)

Opened 5 years ago

Last modified 5 years ago

jquery.eq() wrong behaviour if passed string

Reported by: stevef_ Owned by: flesler
Priority: minor Milestone: 1.3
Component: core Version: 1.2.6
Keywords: eq Cc:
Blocking: Blocked by:

Description

Copy of ticket #3051, cant believe this was closed!

This wasted a good few hous of my time, surely a string check could be done here to avoid this causing problems for other people in the future.

I would rather see an error thrown rather than a jq object containing multiple results, this is really dangerous behaviour especially if your chaining and inadvertinly set many attributes instead of the one desired.

From 1.2.6 source:

443 eq: function( i ) { 444 return this.slice( i, i + 1 ); 445 }

This works fine when passed an integer. Selects a range when passed a string. For example:

.eq("1")

passes ("1", "11") to slice instead of (1, 2).

Change History

comment:1 Changed 5 years ago by flesler

  • Owner set to flesler
  • Status changed from new to assigned
  • Type changed from bug to enhancement

Ok, just figured a small fix, only one extra byte.

comment:2 Changed 5 years ago by flesler

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

Applied the change at [5754].

comment:3 Changed 5 years ago by Markus.Staab

should be easy to have a unit test for this little bug..

comment:4 Changed 5 years ago by Markus.Staab

  • Status changed from closed to reopened
  • Resolution fixed deleted

comment:5 Changed 5 years ago by flesler

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

Ok, added one simple test at [5755]. That should be enough.

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.