From: Alexander Larsson Date: Tue, 22 Jan 2008 09:38:37 +0000 (+0000) Subject: Canonicalize paths that start with more than two slashes. X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=2544ae3cd69668ea578ac7c19a23dc7c2dcad396;p=dana%2Fcg-glib.git Canonicalize paths that start with more than two slashes. 2008-01-22 Alexander Larsson * glocalfile.c: (canonicalize_filename): Canonicalize paths that start with more than two slashes. * tests/g-file.c: (compare_two_files): (test_g_file_new_for_path): Test the above svn path=/trunk/; revision=6353 --- diff --git a/gio/ChangeLog b/gio/ChangeLog index e14c3127..1a6537fb 100644 --- a/gio/ChangeLog +++ b/gio/ChangeLog @@ -1,3 +1,15 @@ +2008-01-22 Alexander Larsson + + * glocalfile.c: + (canonicalize_filename): + Canonicalize paths that start with more than + two slashes. + + * tests/g-file.c: + (compare_two_files): + (test_g_file_new_for_path): + Test the above + 2008-01-22 Alexander Larsson * glocalfile.c: diff --git a/gio/glocalfile.c b/gio/glocalfile.c index 6cc4f28b..ae856b62 100644 --- a/gio/glocalfile.c +++ b/gio/glocalfile.c @@ -214,6 +214,7 @@ canonicalize_filename (const char *filename) { char *canon, *start, *p, *q; char *cwd; + int i; if (!g_path_is_absolute (filename)) { @@ -226,6 +227,24 @@ canonicalize_filename (const char *filename) start = (char *)g_path_skip_root (canon); + /* POSIX allows double slashes at the start to + * mean something special (as does windows too). + * So, "//" != "/", but more than two slashes + * is treated as "/". + */ + i = 0; + for (p = start - 1; + (p >= canon) && + G_IS_DIR_SEPARATOR (*p); + p--) + i++; + if (i > 2) + { + i -= 1; + start -= i; + memmove (start, start+i, strlen (start+i)+1); + } + p = start; while (*p != 0) { diff --git a/gio/tests/g-file.c b/gio/tests/g-file.c index 69ab077f..01b1f653 100644 --- a/gio/tests/g-file.c +++ b/gio/tests/g-file.c @@ -83,7 +83,7 @@ compare_two_files (const gboolean use_uri, const char *path1, const char *path2) GFile *file1 = NULL; GFile *file2 = NULL; gboolean equal; - + if (use_uri) { file1 = g_file_new_for_uri (path1); @@ -120,7 +120,8 @@ test_g_file_new_for_path (void) {"/", TRUE, 0, "/somedir/../"}, {"/", FALSE, 0, "/somedir/.../"}, {"//tmp/dir1", TRUE, 0, "//tmp/dir1"}, - /* Should not fail: {"/tmp/dir1", TRUE, 0, "///tmp/dir1"}, */ + {"/tmp/dir1", TRUE, 0, "///tmp/dir1"}, + {"/tmp/dir1", TRUE, 0, "////tmp/dir1"}, {"/tmp/dir1", TRUE, 0, "/tmp/./dir1"}, {"/tmp/dir1", TRUE, 0, "/tmp//dir1"}, {"/tmp/dir1", TRUE, 0, "/tmp///dir1///"},