Skip to content

Commit 652f37d

Browse files
committed
Just to be on the safe side :)
Nice library, not a JS expert but maybe we can prevent possible iteration over inherited or unexpected properties
1 parent b3817ab commit 652f37d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

functions/array/array_search.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,22 @@ function array_search(needle, haystack, argStrict) {
3030
needle = new RegExp(needle.source, flags);
3131
}
3232
for (key in haystack) {
33-
if (needle.test(haystack[key])) {
34-
return key;
33+
if(haystack.hasOwnProperty(key)){
34+
if (needle.test(haystack[key])) {
35+
return key;
36+
}
3537
}
3638
}
3739
return false;
3840
}
3941

4042
for (key in haystack) {
41-
if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
42-
return key;
43+
if(haystack.hasOwnProperty(key)){
44+
if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
45+
return key;
46+
}
4347
}
4448
}
4549

4650
return false;
47-
}
51+
}

0 commit comments

Comments
 (0)