Skip to content
Myr

`contains` should handle embedded NULs (fix #1732)

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

authored by Nicolas Williams · committed by Nicolas Williams · parent 4b4fefa · Browse files · 2 files+7 added−1 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+7 added−1 removed

  • tests:+5 added−0 removed
  • other:+2 added−1 removed

2 files+7 added−1 removed

modified:src/jv.c+2 added-1 removed
1340 unmodified lines
1341 r = jv_object_contains(jv_copy(a), jv_copy(b));1342 } else if (jv_get_kind(a) == JV_KIND_ARRAY) {1343 r = jv_array_contains(jv_copy(a), jv_copy(b));1344 } else if (jv_get_kind(a) == JV_KIND_STRING) {1345 r = strstr(jv_string_value(a), jv_string_value(b)) != 0;1345 r = _jq_memmem(jv_string_value(a), jv_string_length_bytes(jv_copy(a)),1346 jv_string_value(b), jv_string_length_bytes(jv_copy(b))) != 0;1347 } else {1348 r = jv_equal(jv_copy(a), jv_copy(b));1349 }1350 jv_free(a);
3 unmodified lines
modified:tests/jq.test+5 added
1089 unmodified lines
1090[("foo" | contains("foo")), ("foobar" | contains("foo")), ("foo" | contains("foobar"))]1091{}1092[true, true, false]10931094# containment operator (embedded NULs!)1095[contains("foo"), contains("\u0000b"), contains("\u0000z"), contains("bar"), contains("baz")]1096"foo\u0000bar"1097[true, true, false, true, false]10981099# Try/catch and general `?` operator1100[.[]|try if . == 0 then error("foo") elif . == 1 then .a elif . == 2 then empty else . end catch .]1101[0,1,2,3]1102["foo","Cannot index number with string \"a\"",3]
422 unmodified lines