From d1e1cd98c2001f903aa2d25cb4574a6e49cbd72c Mon Sep 17 00:00:00 2001 From: Mattias Wadman Date: Tue, 30 Nov 2021 12:51:52 +0100 Subject: [PATCH] decode: Fix walk root depth issue causing dump to indent incorrectly --- pkg/decode/value.go | 3 ++- pkg/interp/dump.go | 4 ---- pkg/interp/testdata/display.fqtest | 1 + 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/decode/value.go b/pkg/decode/value.go index 87e80c5e..65196238 100644 --- a/pkg/decode/value.go +++ b/pkg/decode/value.go @@ -90,7 +90,8 @@ func (v *Value) Walk(opts WalkOpts) error { } rootDepthDelta := 0 - if wv.IsRoot { + // only count switching to a new root + if wv.IsRoot && wv != rootV { rootV = wv rootDepthDelta = 1 } diff --git a/pkg/interp/dump.go b/pkg/interp/dump.go index fe6b3e0d..1137ce61 100644 --- a/pkg/interp/dump.go +++ b/pkg/interp/dump.go @@ -322,10 +322,6 @@ func dump(v *decode.Value, w io.Writer, opts Options) error { if opts.Depth != 0 && depth > opts.Depth { return decode.ErrWalkSkipChildren } - // skip first root level - if rootDepth > 0 { - rootDepth-- - } return fn(v, rootV, depth, rootDepth) } diff --git a/pkg/interp/testdata/display.fqtest b/pkg/interp/testdata/display.fqtest index 59559bb3..4bdc4431 100644 --- a/pkg/interp/testdata/display.fqtest +++ b/pkg/interp/testdata/display.fqtest @@ -427,3 +427,4 @@ $ fq -n '"broken" | mp3 | d' | | | headers: [0] | | | frames: [0] 0x0|62 72 6f 6b 65 6e| |broken| | unknown0: raw bits +# TODO: add root depth test