mirror of
https://github.com/wader/fq.git
synced 2024-11-26 21:55:57 +03:00
Merge pull request #222 from wader/display-path-root-array-incorrect
interp: Paths with a array as root was missing start dot
This commit is contained in:
commit
963a7af0d0
13
format/pcap/testdata/dhcp_little_endian.fqtest
vendored
13
format/pcap/testdata/dhcp_little_endian.fqtest
vendored
@ -1,5 +1,16 @@
|
||||
# from https://wiki.wireshark.org/Development/PcapNg
|
||||
$ fq -d pcapng dv /dhcp_little_endian.pcapng
|
||||
# TODO: move once we can have decode value tests somehow
|
||||
$ fq '.[0].blocks[0]' /dhcp_little_endian.pcapng
|
||||
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.[0].blocks[0]{}:
|
||||
0x00|0a 0d 0d 0a |.... | type: "section_header" (0xa0d0d0a) (Section Header Block)
|
||||
0x00| 1c 00 00 00 | .... | length: 28
|
||||
0x00| 4d 3c 2b 1a | M<+. | byte_order_magic: "little_endian" (0x4d3c2b1a)
|
||||
0x00| 01 00 | .. | major_version: 1
|
||||
0x00| 00 00| ..| minor_version: 0
|
||||
0x10|ff ff ff ff ff ff ff ff |........ | section_length: -1
|
||||
| | | options[0:0]:
|
||||
0x10| 1c 00 00 00 | .... | footer_total_length: 28
|
||||
$ fq dv /dhcp_little_endian.pcapng
|
||||
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.[0:1]: /dhcp_little_endian.pcapng (pcapng) 0x0-0x5fb.7 (1532)
|
||||
| | | [0]{}: section 0x0-0x5fb.7 (1532)
|
||||
| | | blocks[0:7]: 0x0-0x5fb.7 (1532)
|
||||
|
@ -82,7 +82,7 @@ func dumpEx(v *decode.Value, buf []byte, cw *columnwriter.Writer, depth int, roo
|
||||
name = ""
|
||||
}
|
||||
if depth == 0 {
|
||||
name = valuePathDecorated(nameV, deco)
|
||||
name = valuePathExprDecorated(nameV, deco)
|
||||
} else {
|
||||
name = deco.ObjectKey.Wrap(name)
|
||||
}
|
||||
|
@ -216,23 +216,22 @@ func valuePath(v *decode.Value) []interface{} {
|
||||
return parts
|
||||
}
|
||||
|
||||
func valuePathDecorated(v *decode.Value, d Decorator) string {
|
||||
var parts []string
|
||||
func valuePathExprDecorated(v *decode.Value, d Decorator) string {
|
||||
parts := []string{"."}
|
||||
|
||||
for _, p := range valuePath(v) {
|
||||
for i, p := range valuePath(v) {
|
||||
switch p := p.(type) {
|
||||
case string:
|
||||
parts = append(parts, ".", d.ObjectKey.Wrap(p))
|
||||
if i > 0 {
|
||||
parts = append(parts, ".")
|
||||
}
|
||||
parts = append(parts, d.ObjectKey.Wrap(p))
|
||||
case int:
|
||||
indexStr := strconv.Itoa(p)
|
||||
parts = append(parts, fmt.Sprintf("%s%s%s", d.Index.F("["), d.Number.F(indexStr), d.Index.F("]")))
|
||||
}
|
||||
}
|
||||
|
||||
if len(parts) == 0 {
|
||||
return "."
|
||||
}
|
||||
|
||||
return strings.Join(parts, "")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user