serialhex/nano-highlight

Broken regex causing incorrect highlighting

davidhcefx opened this issue · 5 comments

When trying out this project, I found several issues:

  1. Since I added include /path/to/nano-highlight/*.nanorc to my nanorc, the highlighting of .nanorc had been changed. However, even I removed nanorc.nanorc, it is still happening. To my surprise, rcfiles-new.nanorc was the culprit:
    ### all *rc files ( e.g. .bashrc, inputrc, xtermcontrol .... )
    #syntax "rcfiles" "(\.|/)rc$" "(\.|/)control$"
    syntax "rcfiles" "((.ba|ba|c|.c)sh|input|xinit|eix|(.w|w)minet)|gtk|rc$"

Notice the broken regex rc$, which match not only .bashrc but also nanorc. Furthermore, .gtk would be matched instead of .gtkrc. The same issue might also exist in other rc files.

  1. bash.nanorc is colliding its definition of \.sh$ with sh.nanorc. It does not work as a fallback method, but instead a complete overwrite. More worst, the order of which one overwrite which is ambiguous, so it's definitely not a good idea.

Hmm, I had not noticed this. I'm not sure exactly what I want to do about this, but it needs to be fixed. If you have any suggestions let me know. It is probably going to be a while before I have a chance to take a look & fix this myself.

j-f1 commented

A couple of possibilities:

 syntax "rcfiles" "^(\.?(ba|c|z)sh|input|xinit|eix|\.?wminet|gtk)rc$" 
 syntax "rcfiles" "^\.?[^.]+rc$" 

Thanks for your prompt reply! For the possible fixes, I would prefer the first one, but shouldn't we constraint to .inputrc$ instead of inputrc$? eg.

syntax "rcfiles" "\.?((ba|c|z)sh|input|xinit|eix|wminet|gtk)rc$" 

By the way, don't place a starting anchor to the regex, because it is in fact matching the full path! I've edited my above comment.

Fixed by PR#52