Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#16104 closed defect (wontfix)

array.indexOf casts false values (uses == not ===)

Reported by: juk Owned by:
Priority: undecided Milestone: tbd
Component: Core Version: 1.8.0
Keywords: Cc:
Blocked By: Blocking:

Description

dojo/_base/array.indexOf uses weak typing and is not consistent with Array.indexOf:

[""].indexOf(false) == -1
[""].indexOf(0) == -1
[undefined].indexOf(null) == -1
array.indexOf([""], false) == 0
array.indexOf([""], 0) == 0
array.indexOf([undefined], null) == 0

Change History (7)

comment:1 Changed 7 years ago by mm

3 days, core function, no reply.

Thanx for interest !

comment:2 in reply to:  1 Changed 7 years ago by Karl Tiedt

Replying to mm:

3 days, core function, no reply.

Thanx for interest !

Friday... Saturday... Sunday... we are all volunteers, you should not expect immediate 24hr response on the weekends ;)

It will get looked at ASAP.

comment:3 in reply to:  description Changed 7 years ago by Kenneth G. Franqueiro

the dojo/_base/array functions' behavior do not match 1:1 with the native Array methods of the same names (partially because, if I recall correctly, the former pre-date the latter). One example that comes up often is in how the iterative methods treat sparse arrays.

I would figure this is not a "bug" that would be "fixed", due to how it would change behavior that code written by users of Dojo 1.0+ may have been relying upon for years, whether intentionally or not.

Dojo 2.0 will probably do away with these methods in favor of something like es5shim.

comment:4 Changed 6 years ago by bill

FYI, I ran the dijit tests after changing indexOf() to use strict equality. After the fix in [30258], they run fine except for an orthogonal issue uncovered and documented in #16514.

comment:5 Changed 6 years ago by bill

Summary: array.indexOf casts false valuesarray.indexOf casts false values (uses == not ===)

comment:6 Changed 6 years ago by bill

Resolution: wontfix
Status: newclosed

Personally I'd like to have this fixed. But I brought this up on http://thread.gmane.org/gmane.comp.web.dojo.devel/18442 and most people don't want to change the current behavior. And since the array module will likely disappear completely for 2.0, marking this as wontfix.

comment:7 Changed 6 years ago by bill

In [30283]:

change API doc for indexOf() and lastIndexOf() to say that it's using == not ===, refs #16104 !strict

Note: See TracTickets for help on using tickets.