[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mono-patches
Subject:    [Mono-patches] [mono/mono] acb426be: Fix mono_path_canonicalize to not canonicalize the root directo
From:       "Rolf Bjarne Kvinge (rolf () xamarin ! com)" <mono-patches () lists ! ximian ! com>
Date:       2012-03-30 22:15:39
Message-ID: 0000013665ad9f7c-d9f074cf-7e3e-49de-9696-658ceeb27fef-000000 () email ! amazonses ! com
[Download RAW message or body]


   Branch: refs/heads/master
     Home: https://github.com/mono/mono
  Compare: https://github.com/mono/mono/compare/cb1e1e9...acb426b

   Commit: acb426be97d8ba52119f654d000a044a0ba792c8
   Author: Rolf Bjarne Kvinge <rolf@xamarin.com> (rolfbjarne)
     Date: 2012-03-30 22:13:39 GMT
      URL: https://github.com/mono/mono/commit/acb426be97d8ba52119f654d000a044a0ba792c8


Fix mono_path_canonicalize to not canonicalize the root directory to an empty string

Changed paths:
  M mono/tests/Makefile.am
  M mono/utils/mono-path.c
Added paths:
  A mono/tests/mono-path.cs

Modified: mono/tests/Makefile.am
===================================================================
@@ -379,6 +379,7 @@ BASE_TEST_CS_SRC=		\
 	bug-696593.cs	\
 	bug-705140.cs	\
 	bug-1147.cs	\
+	mono-path.cs	\
 	bug-bxc-795.cs
 
 TEST_CS_SRC_DIST=	\

Added: mono/tests/mono-path.cs
===================================================================
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+
+public class Program
+{
+	static bool failure;
+
+	[DllImport ("__Internal")]
+	static extern string mono_path_canonicalize (string input);
+
+	static void CanonicalizeAssert (string input, string expected)
+	{
+		string actual = mono_path_canonicalize (input);
+		if (expected != actual) {
+			failure = true;
+			Console.WriteLine ("ERROR: Expected canonicalization of '{0}' to be '{1}', but it \
was '{2}'.", input, expected, actual); +		} else {
+			Console.WriteLine ("SUCCESS: Canonicalization of '{0}' => '{1}'", input, actual);
+		}
+	}
+	
+	static void CanonicalizeTest ()
+	{
+		bool isWindows = !(((int)Environment.OSVersion.Platform == 4) || \
((int)Environment.OSVersion.Platform == 128)); +
+		if (!isWindows) {
+			CanonicalizeAssert ("", Environment.CurrentDirectory);
+			CanonicalizeAssert ("/", "/");
+			CanonicalizeAssert ("/..", "/");
+			CanonicalizeAssert ("/foo", "/foo");
+			CanonicalizeAssert ("/foo/././", "/foo");
+			CanonicalizeAssert ("/../../foo", "/foo");
+			CanonicalizeAssert ("/foo/", "/foo");
+			CanonicalizeAssert ("/foo/../../../", "/");
+			CanonicalizeAssert ("/foo/../../..", "/");
+		}
+	}
+	
+	public static int Main()
+	{
+		CanonicalizeTest ();
+		return failure ? 1 : 0;
+	}
+}
\ No newline at end of file

Modified: mono/utils/mono-path.c
===================================================================
@@ -33,6 +33,8 @@
 
 /* For Native Client, the above is not true.  Since there is no getcwd we fill */
 /* in the file being passed in relative to '.' and don't resolve it            */
+
+/* There are a couple of tests for this method in mono/test/mono-path.cs */
 gchar *
 mono_path_canonicalize (const char *path)
 {
@@ -90,7 +92,20 @@
 #endif
 	
 	if (dest != lastpos) strcpy (dest, lastpos);
-	return g_strreverse (abspath);
+	
+	g_strreverse (abspath);
+
+	/* We strip away all trailing dir separators. This is not correct for the root \
directory, +	 * since we'll return an empty string, so re-append a dir separator if \
there is none in the +	 * result */
+	if (strchr (abspath, G_DIR_SEPARATOR) == NULL) {
+		int len = strlen (abspath);
+		abspath = g_realloc (abspath, len + 2);
+		abspath [len] = G_DIR_SEPARATOR;
+		abspath [len+1] = 0;
+	}
+
+	return abspath;
 }
 
 /*


_______________________________________________
Mono-patches maillist  -  Mono-patches@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-patches


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic