glib r6353 - in trunk/gio: . tests



Author: alexl
Date: Tue Jan 22 09:38:37 2008
New Revision: 6353
URL: http://svn.gnome.org/viewvc/glib?rev=6353&view=rev

Log:
2008-01-22  Alexander Larsson  <alexl redhat com>

        * 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




Modified:
   trunk/gio/ChangeLog
   trunk/gio/glocalfile.c
   trunk/gio/tests/g-file.c

Modified: trunk/gio/glocalfile.c
==============================================================================
--- trunk/gio/glocalfile.c	(original)
+++ trunk/gio/glocalfile.c	Tue Jan 22 09:38:37 2008
@@ -214,6 +214,7 @@
 {
   char *canon, *start, *p, *q;
   char *cwd;
+  int i;
   
   if (!g_path_is_absolute (filename))
     {
@@ -226,6 +227,24 @@
 
   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)
     {

Modified: trunk/gio/tests/g-file.c
==============================================================================
--- trunk/gio/tests/g-file.c	(original)
+++ trunk/gio/tests/g-file.c	Tue Jan 22 09:38:37 2008
@@ -83,7 +83,7 @@
   GFile *file1 = NULL;
   GFile *file2 = NULL;
   gboolean equal;
-  
+
   if (use_uri)
     {
       file1 = g_file_new_for_uri (path1);
@@ -120,7 +120,8 @@
       {"/", 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///"},



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]