Skip to content
Myr

Fix deletion using assigning empty against arrays (fix #2051)

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 cd8898d · Browse files · 2 files+18 added−5 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+18 added−5 removed

  • tests:+13 added−0 removed
  • other:+5 added−5 removed

2 files+18 added−5 removed

modified:src/builtin.jq+5 added-5 removed
10 unmodified lines
11def add: reduce .[] as $x (null; . + $x);12def del(f): delpaths([path(f)]);13def _assign(paths; $value): reduce path(paths) as $p (.; setpath($p; $value));14def _modify(paths; update):15 reduce path(paths) as $p (.;15 reduce path(paths) as $p ([., []];16 . as $dot17 | null18 | label $out19 | ($dot | getpath($p)) as $v19 | ($dot[0] | getpath($p)) as $v20 | (21 ( $$$$v22 | update23 | (., break $out) as $v24 | $$$$dot25 | setpath($p; $v)25 | setpath([0] + $p; $v)26 ),27 (28 $$$$dot29 | delpaths([$p])29 | setpath([1]; .[1] + [$p])30 )31 )32 );32 ) | . as $dot | $dot[0] | delpaths($dot[1]);33def map_values(f): .[] |= f;3435# recurse36def recurse(f): def r: ., (f | r); r;
242 unmodified lines
modified:tests/jq.test+13 added
1042 unmodified lines
1043"Cannot index object with number"1044{"a":[{"b":5}]}1045{"a":[{"c":3,"b":5}]}10461047# #2051, deletion using assigning empty against arrays1048(.[] | select(. >= 2)) |= empty1049[1,5,3,0,7]1050[1,0]10511052.[] |= select(. % 2 == 0)1053[0,1,2,3,4,5]1054[0,2,4]10551056.foo[1,4,2,3] |= empty1057{"foo":[0,1,2,3,4,5]}1058{"foo":[0,5]}10591060.[2][3] = 11061[4]1062[4, null, [null, null, null, 1]]1063
692 unmodified lines