@@ -1018,11 +1018,19 @@ end
10181018M .escape_path_for_cmd = function (path )
10191019 local escaped_path = vim .fn .fnameescape (path )
10201020 if M .is_windows then
1021- -- on windows, any punctuation preceeded by a `\` needs to have a second `\`
1022- -- added to preserve the path separator. this is a naive replacement and
1021+ -- on windows, some punctuation preceeded by a `\` needs to have a second
1022+ -- `\` added to preserve the path separator. this is a naive replacement and
10231023 -- definitely not bullet proof. if we start finding issues with opening files
1024- -- or changing directories, look here first.
1025- escaped_path = escaped_path :gsub (" \\ %p" , " \\ %1" )
1024+ -- or changing directories, look here first. #1382 was the first regression
1025+ -- from the implementation that used lua's %p to match punctuation, which
1026+ -- did not quite work. the following characters were tested on windows to
1027+ -- be known to require an extra escape character.
1028+ for _ , c in ipairs ({ " &" , " (" , " )" , " ;" , " ^" , " `" }) do
1029+ -- lua doesn't seem to have a problem with an unnecessary `%` escape
1030+ -- (e.g., `%;`), so we can use it to ensure we match the punctuation
1031+ -- for the ones that do (e.g., `%(` and `%^`)
1032+ escaped_path = escaped_path :gsub (" \\ %" .. c , " \\ %1" )
1033+ end
10261034 end
10271035 return escaped_path
10281036end
0 commit comments