Fix has(nan) on arrays to output false
This commit is contained in:
1 parent
14e5e630ed
commit
b5c4c3d67d
2 files changed
+11
-3
No files matched your search
+7
-3
@@ -214,10 +214,14 @@ jv jv_has(jv t, jv k) {
|
|||||||
jv_free(elem);
|
jv_free(elem);
|
||||||
} else if (jv_get_kind(t) == JV_KIND_ARRAY &&
|
} else if (jv_get_kind(t) == JV_KIND_ARRAY &&
|
||||||
jv_get_kind(k) == JV_KIND_NUMBER) {
|
jv_get_kind(k) == JV_KIND_NUMBER) {
|
||||||
jv elem = jv_array_get(t, (int)jv_number_value(k));
|
if (jvp_number_is_nan(k)) {
|
||||||
ret = jv_bool(jv_is_valid(elem));
|
ret = jv_false();
|
||||||
|
} else {
|
||||||
|
jv elem = jv_array_get(t, (int)jv_number_value(k));
|
||||||
|
ret = jv_bool(jv_is_valid(elem));
|
||||||
|
jv_free(elem);
|
||||||
|
}
|
||||||
jv_free(k);
|
jv_free(k);
|
||||||
jv_free(elem);
|
|
||||||
} else {
|
} else {
|
||||||
ret = jv_invalid_with_msg(jv_string_fmt("Cannot check whether %s has a %s key",
|
ret = jv_invalid_with_msg(jv_string_fmt("Cannot check whether %s has a %s key",
|
||||||
jv_kind_name(jv_get_kind(t)),
|
jv_kind_name(jv_get_kind(t)),
|
||||||
|
|||||||
@@ -1389,6 +1389,10 @@ map(has(2))
|
|||||||
[[0,1], ["a","b","c"]]
|
[[0,1], ["a","b","c"]]
|
||||||
[false, true]
|
[false, true]
|
||||||
|
|
||||||
|
has(nan)
|
||||||
|
[0,1,2]
|
||||||
|
false
|
||||||
|
|
||||||
keys
|
keys
|
||||||
[42,3,35]
|
[42,3,35]
|
||||||
[0,1,2]
|
[0,1,2]
|
||||||
|
|||||||
Reference in new issue
Block a user