fiatjaf / jiq

jid on jq - interactive JSON query tool using jq expressions
MIT License
919 stars 32 forks source link

Breaks when pressing <delete> on empty query #31

Open pmf-ids opened 2 years ago

pmf-ids commented 2 years ago

When calling jiq with

echo 1 | jiq

it opens up fine, displaying

[jq]> .

1

with the cursor being next to the dot. Hitting backspace removes the dot (which is expected behaviour). Hitting backspace again does nothing (also as expected). Now, hitting delete makes jiq crash with the message

panic: runtime error: slice bounds out of range [1:0]

goroutine 1 [running]:
github.com/fiatjaf/jiq.(*Query).Delete(0xc0002a6030, 0x0, 0x0, 0x0, 0x0)
    /home/fiatjaf/comp/jiq/query.go:58 +0x238
github.com/fiatjaf/jiq.(*Engine).Run(0xc0002d2000, 0x0)
    /home/fiatjaf/comp/jiq/engine.go:126 +0xaa8
main.run(0xc0002d2000, 0xc0002a6000, 0xc00028c1f0)
    /home/fiatjaf/comp/jiq/cmd/jiq/jiq.go:59 +0x32
main.main()
    /home/fiatjaf/comp/jiq/cmd/jiq/jiq.go:55 +0x18d

This does not happen when hitting delete while the dot (or any other filter) is still visible.

Tested on jiq version 0.7.1-3-g5dec899