Skip to content

Conversation

equalsraf
Copy link
Contributor

@equalsraf equalsraf force-pushed the windows-path-is-absolute branch from 219ada0 to 1ee7a53 Compare August 9, 2016 14:22
@equalsraf equalsraf changed the title Add Windows support to path_is_absolute() [RFC] Add Windows support to path_is_absolute() Aug 10, 2016
@marvim marvim added the RFC label Aug 10, 2016
@equalsraf equalsraf force-pushed the windows-path-is-absolute branch 2 times, most recently from be7ba16 to 48bd0be Compare August 13, 2016 22:54
@equalsraf
Copy link
Contributor Author

Fixed lint errors

/// @return `TRUE` if "fname" is absolute.
int path_is_absolute_path(const char_u *fname)
{
#ifdef WIN32
// A name like "d:/foo" and "//server/share" is absolute
return ((fname[0] && fname[1] == ':' && (fname[2] == '/' || fname[2] == '\\'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In get_past_head() we used isalpha(fname[0]) instead of fname[0] to check for 'd' in "d:". Why is it not used here?

@equalsraf
Copy link
Contributor Author

Looking at it the check could be changed into

(isalpha(fname[0]) && fname[1] == ':' && vim_ispathsep_nocolon(fname[2]))
|| (vim_ispathsep_nocolon(fname[0]) && fname[0] == fname[1])

@equalsraf equalsraf force-pushed the windows-path-is-absolute branch from e743f39 to f76aaec Compare August 14, 2016 21:03
// A name like "d:/foo" and "//server/share" is absolute
return (isalpha(fname[0]) && fname[1] == ':'
&& vim_ispathsep_nocolon(fname[2]))
|| (fname[0] == fname[1] && vim_ispathsep_nocolon(fname[0]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If fname can be an empty string, the check fname[0] == fname[1] should not be used (here), because fname[1] is not part of the string. The arguments of && could be switched to fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@equalsraf equalsraf force-pushed the windows-path-is-absolute branch from f76aaec to 62c7dec Compare August 15, 2016 11:59
/// @return `TRUE` if "fname" is absolute.
int path_is_absolute_path(const char_u *fname)
{
#ifdef WIN32
// A name like "d:/foo" and "//server/share" is absolute
return (isalpha(fname[0]) && fname[1] == ':'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIR isalpha is locale-dependent and may return true unexpectedly if locale happens to be non-UTF-8 (and, theoretically, it may return unexpected false if locale is not C, but I doubt you will find any locale which rejects latin letters). I would suggest using not C library, but our ascii_isalpha function from src/nvim/lib/ascii.h.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to deal with this one separately. The use of isalpha is similar to what is done in vim/vim and there are a least a couple other locations, unrelated to this PR, where isalpha is used.

@equalsraf
Copy link
Contributor Author

Poked travis, builds look ok now.

/// @return `TRUE` if "fname" is absolute.
int path_is_absolute_path(const char_u *fname)
{
#ifdef WIN32
// A name like "d:/foo" and "//server/share" is absolute
return ((isalpha(fname[0]) && fname[1] == ':'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vim's mch_isFullName doesn't check isalpha. Apparently old versions of Windows supported non-alpha drive letters.

@justinmk justinmk merged commit 6f0f8e7 into neovim:master Aug 18, 2016
@jamessan
Copy link
Member

What about UNC paths?

@justinmk
Copy link
Member

UNC paths are covered by the

(vim_ispathsep_nocolon(fname[0]) && fname[0] == fname[1])

condition.

@equalsraf equalsraf deleted the windows-path-is-absolute branch August 31, 2016 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants