Skip to content
Myr

Change contains to return true for empty string needles

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

The behavior of memmem for an empty needle is inconsistent between implementations of libc. Our tests imply that we want an empty string needle to be true, so check for an empty needle before calling memmem.

authored by William Langford · committed by Nico Williams · parent cc724f1 · Browse files · 1 file+7 added−2 removed
This commit

State

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

Diff stats

1 file+7 added−2 removed

  • other:+7 added−2 removed

1 file+7 added−2 removed

modified:src/jv.c+7 added-2 removed
1342 unmodified lines
1343 r = jv_object_contains(jv_copy(a), jv_copy(b));1344 } else if (jv_get_kind(a) == JV_KIND_ARRAY) {1345 r = jv_array_contains(jv_copy(a), jv_copy(b));1346 } else if (jv_get_kind(a) == JV_KIND_STRING) {1347 int b_len = jv_string_length_bytes(jv_copy(b));1348 if (b_len != 0) {1347 r = _jq_memmem(jv_string_value(a), jv_string_length_bytes(jv_copy(a)),1348 jv_string_value(b), jv_string_length_bytes(jv_copy(b))) != 0;1349 r = _jq_memmem(jv_string_value(a), jv_string_length_bytes(jv_copy(a)),1350 jv_string_value(b), b_len) != 0;1351 } else {1352 r = 1;1353 }1354 } else {1355 r = jv_equal(jv_copy(a), jv_copy(b));1356 }1357 jv_free(a);
3 unmodified lines