Fix has(nan) on arrays to output false

This commit is contained in:
itchyny authored and Nico Williams committed 2023-07-12 09:40:05 -05:00
1 parent 14e5e630ed
commit b5c4c3d67d
2 files changed
+11 -3

No files matched your search

+7 -3
View File
@@ -214,10 +214,14 @@ jv jv_has(jv t, jv k) {
jv_free(elem);
} else if (jv_get_kind(t) == JV_KIND_ARRAY &&
jv_get_kind(k) == JV_KIND_NUMBER) {
jv elem = jv_array_get(t, (int)jv_number_value(k));
ret = jv_bool(jv_is_valid(elem));
if (jvp_number_is_nan(k)) {
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(elem);
} else {
ret = jv_invalid_with_msg(jv_string_fmt("Cannot check whether %s has a %s key",
jv_kind_name(jv_get_kind(t)),
+4
View File
@@ -1389,6 +1389,10 @@ map(has(2))
[[0,1], ["a","b","c"]]
[false, true]
has(nan)
[0,1,2]
false
keys
[42,3,35]
[0,1,2]