Error when directory name contains underscore
I've created minimal test project. This is on Windows. All files reside in directory d:\_t.
meson.build:
project('foo', 'cpp')
executable('foo', 'foo.cpp')
foo.cpp
int main() {
return 0;
}
When I open foo.cpp in NeoVim with Mesonic installed, it throws an error while opening the file:
Error detected whiler processing BufReadPost Autocommands for "*"..script C:\Users\...\AppData\Local\nvim-data\lazy\mesonic\compiler\meson.vim[85]..function <SNR>33_SetErrorFormat[15]..<SNR>33_GetCwdRelativeToProjectDirectory:
line 1:
E877: (NFA regexp) Invalid character class 116
Note that character 116 = t. If you rename the directory to _x, the error goes away.
The error also happens with _b (character 98), but not with _a, etc...
@vid512 Does it work if _t directory is not at the root of the drive?
For example: D:\some-dir\_t?
Same problem. Combination of directory name starting with underscore + some characters (t, b, ...) anywhere in path seems to trigger this. Also D:\some-dir\_t\somedir, D:\a\_test\b, etc. However, I couldn't replicate this with underscore in the middle of directory name, only at the beginning.
Problem is in function GetCwdRelativeToProjectDirectory.
https://github.com/igankevich/mesonic/blob/69a3a1e03b94d4d41f94dfe243edbe87069c22f1/compiler/meson.vim#L10-L12
The fnameescape apparently doesn't escape good enough for substitute.
I was able to get rid of the bug by changing the function to this code:
function! s:GetCwdRelativeToProjectDirectory(project_dir)
let l:cwd = getcwd()
if l:cwd[0:len(a:project_dir)-1] ==# a:project_dir
return l:cwd[len(a:project_dir)]
else
return l:cwd
endif
endfunction
(Make sure to check the code for any pitfalls. I know next to nothing about vimscript.)
I was able to get rid of the bug by changing the function to this code:
Thank you! I fixed this issue in https://github.com/igankevich/mesonic/commit/d6780c3af29ebfc8c631399b2692b928da9bf7bd. Better late than never I guess.