1
1
mirror of https://github.com/wader/fq.git synced 2024-12-23 13:22:58 +03:00

decode: Fix walk root depth issue causing dump to indent incorrectly

This commit is contained in:
Mattias Wadman 2021-11-30 12:51:52 +01:00
parent 8d442b82ee
commit d1e1cd98c2
3 changed files with 3 additions and 5 deletions

View File

@ -90,7 +90,8 @@ func (v *Value) Walk(opts WalkOpts) error {
} }
rootDepthDelta := 0 rootDepthDelta := 0
if wv.IsRoot { // only count switching to a new root
if wv.IsRoot && wv != rootV {
rootV = wv rootV = wv
rootDepthDelta = 1 rootDepthDelta = 1
} }

View File

@ -322,10 +322,6 @@ func dump(v *decode.Value, w io.Writer, opts Options) error {
if opts.Depth != 0 && depth > opts.Depth { if opts.Depth != 0 && depth > opts.Depth {
return decode.ErrWalkSkipChildren return decode.ErrWalkSkipChildren
} }
// skip first root level
if rootDepth > 0 {
rootDepth--
}
return fn(v, rootV, depth, rootDepth) return fn(v, rootV, depth, rootDepth)
} }

View File

@ -427,3 +427,4 @@ $ fq -n '"broken" | mp3 | d'
| | | headers: [0] | | | headers: [0]
| | | frames: [0] | | | frames: [0]
0x0|62 72 6f 6b 65 6e| |broken| | unknown0: raw bits 0x0|62 72 6f 6b 65 6e| |broken| | unknown0: raw bits
# TODO: add root depth test