fix(path): normalize path slashes on Windows #37729

Problem:
On Windows, path separators may become inconsistent for various reasons,
which makes normalization quite painful.

Solution:
Normalize paths to `/` at the entry boundaries and always use it
internally, converting back only in rare cases where `\` is really
needed (e.g. cmd.exe/bat scripts?).

This is the first commit in a series of incremental steps.

Note:
* some funcs won't respect shellslash. e.g. `expand/fnamemodify`
* some funcs still respect shellslash, but will be updated in a follow
  PR. e.g. `ex_pwd/f_chdir/f_getcwd`
* uv's built-in funcs always return `\`. e.g. `uv.cwd/uv.exepath`

Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
This commit is contained in:
tao
2026-04-25 01:20:25 +08:00
committed by GitHub
parent 27191e0f4f
commit f130922744
41 changed files with 203 additions and 216 deletions

View File

@@ -85,7 +85,7 @@ describe('backtick expansion', function()
eq({ 'file2' }, eval('argv()'))
if t.is_os('win') then
command(':silent args `dir /s/b *4`')
eq({ 'subdir\\file4' }, eval('map(argv(), \'fnamemodify(v:val, ":.")\')'))
eq({ 'subdir/file4' }, eval('map(argv(), \'fnamemodify(v:val, ":.")\')'))
else
command(':silent args `echo */*4`')
eq({ 'subdir/file4' }, eval('argv()'))