Require UNC paths to start with exactly two slashes. (g_path_get_dirname):

2004-12-30  Tor Lillqvist  <tml@iki.fi>

	* glib/gutils.c (g_path_skip_root): Require UNC paths to start
	with exactly two slashes.
	(g_path_get_dirname): Handle UNC paths better. Part of fix for
	#161797.
This commit is contained in:
Tor Lillqvist 2004-12-30 02:04:41 +00:00 committed by Tor Lillqvist
parent 1a6fe2c7b7
commit e0923069df
6 changed files with 77 additions and 2 deletions

View File

@ -1,3 +1,10 @@
2004-12-30 Tor Lillqvist <tml@iki.fi>
* glib/gutils.c (g_path_skip_root): Require UNC paths to start
with exactly two slashes.
(g_path_get_dirname): Handle UNC paths better. Part of fix for
#161797.
2004-12-11 Tor Lillqvist <tml@iki.fi>
* glib/gspawn-win32.c: Fix #157255. Also some refactoring of this

View File

@ -1,3 +1,10 @@
2004-12-30 Tor Lillqvist <tml@iki.fi>
* glib/gutils.c (g_path_skip_root): Require UNC paths to start
with exactly two slashes.
(g_path_get_dirname): Handle UNC paths better. Part of fix for
#161797.
2004-12-11 Tor Lillqvist <tml@iki.fi>
* glib/gspawn-win32.c: Fix #157255. Also some refactoring of this

View File

@ -1,3 +1,10 @@
2004-12-30 Tor Lillqvist <tml@iki.fi>
* glib/gutils.c (g_path_skip_root): Require UNC paths to start
with exactly two slashes.
(g_path_get_dirname): Handle UNC paths better. Part of fix for
#161797.
2004-12-11 Tor Lillqvist <tml@iki.fi>
* glib/gspawn-win32.c: Fix #157255. Also some refactoring of this

View File

@ -1,3 +1,10 @@
2004-12-30 Tor Lillqvist <tml@iki.fi>
* glib/gutils.c (g_path_skip_root): Require UNC paths to start
with exactly two slashes.
(g_path_get_dirname): Handle UNC paths better. Part of fix for
#161797.
2004-12-11 Tor Lillqvist <tml@iki.fi>
* glib/gspawn-win32.c: Fix #157255. Also some refactoring of this

View File

@ -1,3 +1,10 @@
2004-12-30 Tor Lillqvist <tml@iki.fi>
* glib/gutils.c (g_path_skip_root): Require UNC paths to start
with exactly two slashes.
(g_path_get_dirname): Handle UNC paths better. Part of fix for
#161797.
2004-12-11 Tor Lillqvist <tml@iki.fi>
* glib/gspawn-win32.c: Fix #157255. Also some refactoring of this

View File

@ -521,7 +521,8 @@ g_path_skip_root (const gchar *file_name)
/* Skip \\server\share or //server/share */
if (G_IS_DIR_SEPARATOR (file_name[0]) &&
G_IS_DIR_SEPARATOR (file_name[1]) &&
file_name[2])
file_name[2] &&
!G_IS_DIR_SEPARATOR (file_name[2]))
{
gchar *p;
@ -606,8 +607,47 @@ g_path_get_dirname (const gchar *file_name)
base--;
#ifdef G_OS_WIN32
/* base points to the char before the last slash.
*
* In case file_name is the root of a drive (X:\) or a child of the
* root of a drive (X:\foo), include the slash.
*
* In case file_name is the root share of an UNC path
* (\\server\share), add a slash, returning \\server\share\ .
*
* In case file_name is a direct child of a share in an UNC path
* (\\server\share\foo), include the slash after the share name,
* returning \\server\share\ .
*/
if (base == file_name + 1 && g_ascii_isalpha (file_name[0]) && file_name[1] == ':')
base++;
else if (G_IS_DIR_SEPARATOR (file_name[0]) &&
G_IS_DIR_SEPARATOR (file_name[1]) &&
file_name[2] &&
!G_IS_DIR_SEPARATOR (file_name[2]) &&
base >= file_name + 2)
{
const gchar *p = file_name + 2;
while (*p && !G_IS_DIR_SEPARATOR (*p))
p++;
if (p == base + 1)
{
len = (guint) strlen (file_name) + 1;
base = g_new (gchar, len + 1);
strcpy (base, file_name);
base[len-1] = G_DIR_SEPARATOR;
base[len] = 0;
return base;
}
if (G_IS_DIR_SEPARATOR (*p))
{
p++;
while (*p && !G_IS_DIR_SEPARATOR (*p))
p++;
if (p == base + 1)
base++;
}
}
#endif
len = (guint) 1 + base - file_name;