dandavison / delta

A syntax-highlighting pager for git, diff, grep, and blame output
https://dandavison.github.io/delta/
MIT License
21.32k stars 358 forks source link

🐛 ripgrep JSON output causes panic with UTF character #1679

Open mmottl opened 2 months ago

mmottl commented 2 months ago

Consider the following text file containing a UTF character followed by newline:

❯ cat foo.txt
━

Here is the hex dump for clarity:

❯ xxd -p foo.txt
e294810a

Delta will interpret regular rg output just fine:

❯ rg "" foo.txt | delta
━

But it will panic when using JSON output:

❯ rg --json "" foo.txt | RUST_BACKTRACE=1 delta
thread 'main' panicked at src/handlers/grep.rs:389:50:
byte index 1 is not a char boundary; it is inside '━' (bytes 0..3) of `━`
stack backtrace:
• foo.txt
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::str::slice_error_fail_rt
   3: core::str::slice_error_fail
   4: delta::handlers::grep::make_style_sections
   5: delta::handlers::grep::<impl delta::delta::StateMachine>::handle_grep_line
   6: delta::delta::delta
   7: delta::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.