Christian Brabandt wrote:

> there seems to be a problem with backslash escaped strings when using 
> expand(), glob() or globpath():
> 
> #v+
> cb@host: mkdir -p /tmp/test
> ch@host: touch /tmp/test/bar /tmp/teest/foo\\1
> cb@host: vim -u NONE -U NONE -N -c ':e /tmp/test/bar|echo 
> expand(@#)|echo expand("#")' /tmp/test/foo\\1
> #v-
> 
> This outputs:
> "/tmp/test/bar" 0L, 0C
> test/foo1
> test/foo\1
> 
> The problem is, you can't rely on expand() to skip one backslash, 
> because on Windows it behaves correctly (e.g. expand('foobar\1') on 
> Windows returns 'foobar\1' while on Unixs returns 'foobar1').

Yeah, handling a backslash in a filename gets tricky on MS-Windows, you
don't always know if it is used as a path separator or to escape the
special meaning of a character.

On the command line backslashes are accepted as path separators on
Windows, thus it will be different from Unix.  That is intentional and
should not be changed.

For functions it gets tricky.  And then we also have 'shellslash'.  Thus
it probably won't ever be consistent.


> Also, you can't use glob('/tmp/test/foo\\1') to return the correct 
> result, and if you use glob(expand(path)) where path contains a 
> backslash, glob() won't return the empty string.
> 
> This is problematic because glob() is mentioned below :h filereadable() 
> to check for the existence of a file.

Why would you use "\\1" here?  It doesn't have a special meaning, thus
perhaps the user actually wanted two backslashes?

> Here is a patch, that fixes this problematic behaviour and makes it at 
> least consistent to the Windows behaviour. But ... it is a backward 
> incompatible change and probably breaks a lot of plugins, that work 
> around that bug by using something like
> 
> if glob(expand(escape(filename, '\\')))
>      " file exists
>      &
> else
>      " create file
>      &
> endif
> 
> Nevertheless, I tend to consider this as a bug and would like it to work 
> consistently on all plattforms.

As mentioned, consistency is not really a goal here, MS-Windows handles
backslashes differently.  We need a better reason to make backwards
incompatible changes.


-- 
hundred-and-one symptoms of being an internet addict:
26. You check your mail. It says "no new messages." So you check it again.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui