Bat: Hang when displaying yaml with comment at start of line

Created on 21 Nov 2018  Β·  3Comments  Β·  Source: sharkdp/bat

When using bat on YAML files that include comments which start at the beginning of a line, that is, the first character of the line is a #, bat will hang indefinitely, and never finish displaying the file.

Contents of working file via cat:

$ cat works.yml
test: value

still: okay

 # comment with hash character at beginning of line, but with a space first

will: reach here

Contents of working file via bat:

$ bat works.yml
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       β”‚ File: works.yml
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   β”‚ test: value
   2   β”‚
   3   β”‚ still: okay
   4   β”‚
   5   β”‚  # comment with hash character at beginning of line, but with a space first
   6   β”‚
   7   β”‚ will: reach here
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
$

Without the leading space in the comment line

Contents of broken file via cat:

$ cat broken.yml
test: value

still: okay

# comment with hash character at beginning of line

will: not reach here

Contents of working file via bat:

$ bat broken.yml
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       β”‚ File: broken.yml
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   β”‚ test: value
   2   β”‚
   3   β”‚ still: okay
   4   β”‚

From this point on, it will linger forever and never finish. Even the comment line isn't shown. Something seems to be wrong with the syntax parsing in this case.

It _does_ work with the -A flag enabled:

$ bat -A broken.yml
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       β”‚ File: broken.yml
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   β”‚ test:β€’value␊
   2   β”‚ ␊
   3   β”‚ still:β€’okay␊
   4   β”‚ ␊
   5   β”‚ #β€’commentβ€’withβ€’hashβ€’characterβ€’atβ€’beginningβ€’ofβ€’line␊
   6   β”‚ ␊
   7   β”‚ will:β€’notβ€’reachβ€’here␊
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
$

It is consistently repeatable. Different values of --style do not change the outcome, it hangs every time.

$ bat --version
bat 0.9.0

bat installed via Homebrew on OS X Mojave.

Darwin Kernel Version 18.2.0: Fri Oct  5 19:41:49 PDT 2018; root:xnu-4903.221.2~2/RELEASE_X86_64 x86_64

All 3 comments

there was a similar issue which was fixed upstream: https://github.com/trishume/syntect/issues/219
I wonder what is happening in this case

@tomgoren Thank you for the detailed bug report!

I can not reproduce this.

This looks very much like the bug that I have reported upstream, as @keith-hall mentioned. It only appeared if a syntax set was dumped to disk and reloaded again.

Did you use bat cache --init in the past (with an older version of bat)? Can you try to run

bat cache --clear

to see if the error goes away?

If that is the case, you should be able to run bat cache --init again without any issues.

Holy moly @sharkdp - that fixed it! Thanks. Sorry for any confusion.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SamuelMarks picture SamuelMarks  Β·  3Comments

mjlbach picture mjlbach  Β·  3Comments

jkaan picture jkaan  Β·  3Comments

gAmUssA picture gAmUssA  Β·  3Comments

yum-feng picture yum-feng  Β·  3Comments