1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Fix has(nan) on arrays to output false

This commit is contained in:
itchyny
2023-07-08 16:58:04 +09:00
committed by Nico Williams
parent 14e5e630ed
commit b5c4c3d67d
2 changed files with 11 additions and 3 deletions

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)),

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]