Better support for UNC paths in tr_sys_path_is_relative

Accept \\ and // and valid UNC path prefixes, but not \/ or /\.
This commit is contained in:
Mike Gelfand 2015-10-23 03:55:04 +00:00
parent 5f420cafda
commit abb572fe26
2 changed files with 9 additions and 3 deletions

View File

@ -333,16 +333,22 @@ test_path_is_relative (void)
#ifdef _WIN32
check (tr_sys_path_is_relative ("/"));
check (tr_sys_path_is_relative ("//x"));
check (tr_sys_path_is_relative ("\\x"));
check (tr_sys_path_is_relative ("/x"));
check (tr_sys_path_is_relative ("\\x\\y"));
check (tr_sys_path_is_relative ("/x/y"));
check (tr_sys_path_is_relative ("C:x"));
check (tr_sys_path_is_relative ("C:x\\y"));
check (tr_sys_path_is_relative ("C:x/y"));
check (!tr_sys_path_is_relative ("\\\\"));
check (!tr_sys_path_is_relative ("//"));
check (!tr_sys_path_is_relative ("\\\\x"));
check (!tr_sys_path_is_relative ("//x"));
check (!tr_sys_path_is_relative ("\\\\x\\y"));
check (!tr_sys_path_is_relative ("//x/y"));
check (!tr_sys_path_is_relative ("\\\\.\\x"));
check (!tr_sys_path_is_relative ("//./x"));
check (!tr_sys_path_is_relative ("a:"));
check (!tr_sys_path_is_relative ("a:\\"));

View File

@ -367,11 +367,11 @@ tr_sys_path_is_relative (const char * path)
assert (path != NULL);
/* UNC path: `\\...`. */
if (path[0] == '\\' && path[1] == '\\')
if (is_unc_path (path))
return false;
/* Local path: `X:` or `X:\...`. */
if (isalpha (path[0]) && path[1] == ':' && (path[2] == '\0' || path[2] == '\\' || path[2] == '/'))
if (isalpha (path[0]) && path[1] == ':' && (path[2] == '\0' || is_slash (path[2])))
return false;
return true;