Skip to content
Myr

Fix has(nan) on arrays to output false

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by itchyny · committed by Nico Williams · parent 14e5e63 · Browse files · 2 files+11 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+11 added−3 removed

  • tests:+4 added−0 removed
  • other:+7 added−3 removed

2 files+11 added−3 removed

modified:src/jv_aux.c+7 added-3 removed
212 unmodified lines
213 ret = jv_bool(jv_is_valid(elem));214 jv_free(elem);215 } else if (jv_get_kind(t) == JV_KIND_ARRAY &&216 jv_get_kind(k) == JV_KIND_NUMBER) {217 if (jvp_number_is_nan(k)) {218 ret = jv_false();219 } else {217 jv elem = jv_array_get(t, (int)jv_number_value(k));218 ret = jv_bool(jv_is_valid(elem));220 jv elem = jv_array_get(t, (int)jv_number_value(k));221 ret = jv_bool(jv_is_valid(elem));222 jv_free(elem);223 }224 jv_free(k);220 jv_free(elem);225 } else {226 ret = jv_invalid_with_msg(jv_string_fmt("Cannot check whether %s has a %s key",227 jv_kind_name(jv_get_kind(t)),228 jv_kind_name(jv_get_kind(k))));
462 unmodified lines
modified:tests/jq.test+4 added
1387 unmodified lines
1388map(has(2))1389[[0,1], ["a","b","c"]]1390[false, true]13911392has(nan)1393[0,1,2]1394false13951396keys1397[42,3,35]1398[0,1,2]1399
405 unmodified lines