[Mono-bugs] [Bug 42303][Nor] Changed - Path.GetFullPath () does not handle '.' and '..'

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Tue, 6 May 2003 06:40:28 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by gfr@skynet.be.

http://bugzilla.ximian.com/show_bug.cgi?id=42303

--- shadow/42303	Mon May  5 19:02:17 2003
+++ shadow/42303.tmp.13411	Tue May  6 06:40:28 2003
@@ -1,13 +1,13 @@
 Bug#: 42303
 Product: Mono/Class Libraries
 Version: unspecified
 OS: unknown
 OS Details: Red Hat 9 + libgc,mono,mcs up-to-date from cvs
-Status: RESOLVED   
-Resolution: FIXED
+Status: REOPENED   
+Resolution: 
 Severity: Unknown
 Priority: Normal
 Component: CORLIB
 AssignedTo: bmaurer@users.sf.net                            
 ReportedBy: gfr@skynet.be               
 QAContact: mono-bugs@ximian.com
@@ -141,6 +141,249 @@
 ------- Additional Comments From bmaurer@users.sf.net  2003-05-05 18:25 -------
 Ok, function written. Now I need to write NUnit tests before this gets
 checked in.
 
 ------- Additional Comments From bmaurer@users.sf.net  2003-05-05 19:02 -------
 Fixed in CVS
+
+------- Additional Comments From gfr@skynet.be  2003-05-06 06:40 -------
+Hello Ben,
+
+I don't know how to write a test unit with NUnit (i've not yet the 
+time to look coorectly to NUnit).
+
+Some case are not yet supported by the new implementation.
+
+I've write yesterday a more powerfull sample with one examples which
+fake the Path.GetFullPath () from microsoft and compare the result 
+from the fake method ant the microsoft method.
+
+Only the test L38 to L39 are not yet resolved and could create some 
+probleme for a full compatibility.
+
+This case is '//servername/path' ... MS assume than if the path start
+with // then the path is an UNC path.
+
+If you desire, i can try to fix my method code this week in order to 
+be fully compliant with the MS method and allow a correct 
+implementation under Unix with support for UNC.
+
+This is my test code. All test return success under MS Dotnet Window.
+
+Best Regards,
+Gilles
+
+>>> SOT >>>
+using System;
+using System.Text;
+using System.IO;
+using System.Collections;
+
+namespace Test6
+{
+	public class Test6
+	{
+		public static System.String GetFullPath 
+(System.String path)
+		{
+			Stack			  stack   = new 
+Stack         ();
+			StringBuilder	  builder = new 
+StringBuilder ();
+			System.String     volume  = null;
+			System.String  [] split;
+
+			if (Path.IsPathRooted (path) == false)
+			{
+				path = Path.Combine 
+(Directory.GetCurrentDirectory (), path);
+			}
+
+			if (Path.VolumeSeparatorChar != 
+Path.DirectorySeparatorChar &&
+			    Path.VolumeSeparatorChar != 
+Path.AltDirectorySeparatorChar)
+			{
+				split = path.Split   
+(Path.VolumeSeparatorChar);
+				if (split.Length == 2)
+				{
+					volume  = split[0];
+					path    = split[1];
+				}
+				else
+				{
+					split  = Path.GetPathRoot 
+(Directory.GetCurrentDirectory ()).Split (Path.VolumeSeparatorChar);
+					volume = split.Length == 2 ? 
+split[0] : null;
+				}
+			}
+
+			foreach (System.String directoryName in 
+path.Split (Path.AltDirectorySeparatorChar, 
+Path.DirectorySeparatorChar))
+			{
+				if (directoryName.Length == 0)
+				{
+					continue;
+				}
+
+#if             MS_NOT_BUGGED
+				System.String directory = 
+directoryName;
+#else           
+				System.String directory = 
+directoryName.Trim (' ');
+#endif
+
+				if (directory.Length == 0)
+				{
+					throw new ArgumentException 
+("The path is not of a legal form.");
+				}
+
+				if (directory == ".")
+				{
+					continue;
+				}
+
+				if (directory == "..")
+				{
+					if (stack.Count > 0)
+					{
+						stack.Pop ();
+					}
+
+					continue;
+				}
+
+				stack.Push (directory);
+			}
+
+			System.Object [] rst = stack.ToArray ();
+			stack.Clear ();
+
+			if (volume != null)
+			{
+				builder.Append (volume)
+					   .Append 
+(Path.VolumeSeparatorChar)
+					   .Append 
+(Path.DirectorySeparatorChar);
+			}
+			else
+			{
+				builder.Append 
+(Path.DirectorySeparatorChar);
+			}
+
+			for (System.Int32 i=rst.Length-1; i>=0; i--)
+			{
+				builder.Append ((System.String) rst
+[i]);
+
+				if (i != 0)
+				{
+					builder.Append 
+(Path.DirectorySeparatorChar);
+				}
+			}
+
+			if (path.Length > 0 &&
+				builder.Length > 0 &&
+				builder[builder.Length-1] != 
+Path.DirectorySeparatorChar &&
+				(path[path.Length-1] == 
+Path.AltDirectorySeparatorChar ||
+				 path[path.Length-1] == 
+Path.DirectorySeparatorChar))
+			{
+				builder.Append 
+(Path.DirectorySeparatorChar);
+			}
+
+			return builder.ToString ();
+		}
+    
+		public static void Test (System.String label, 
+System.String Expanded)
+		{
+			System.String compacted = GetFullPath 
+(Expanded);
+			System.String expanded  = Path.GetFullPath 
+(Expanded);
+
+			if (expanded == compacted)
+			{
+				System.Console.Out.WriteLine ("Test -
+ {0, -3} - success : expanded = compacted = '{1}'", label, expanded);
+			}
+			else
+			{
+				System.Console.Out.WriteLine ("Test -
+ {0, -3} - fail    : expanded '{1}' and compacted = '{2}'", 
+					label, expanded, compacted);
+			}
+		}
+    
+		public static void Main ()
+		{
+			System.Console.WriteLine ("Current Directory 
+is {0}", Directory.GetCurrentDirectory());
+
+			Test 
+("L1",  "/root/././././././../root/././../root");
+			Test 
+("L2",  "c:/windows/././././././../windows/././../windows");
+			Test ("L3",  "/root/");
+			Test ("L4",  "/root/./");
+			Test ("L5",  "/root/./");
+			Test ("L6",  "/root/../");
+			Test ("L7",  "../");
+			Test ("L8",  "./");
+			Test ("L9",  "/root/../");
+			Test ("L10", "/root/../..");
+			Test ("L11", "c:/windows/../..");
+			Test ("L12", "c:/windows/../..");
+			Test ("L13", "/root/.hiddenfile");
+			Test ("L14", "/root/. /");
+			Test ("L15", "/root/.. /");
+			Test ("L16", "/root/..weirdname");
+			Test ("L17", "/root/..");
+			Test ("L18", "/root/../a/b/../../..");
+			Test ("L19", "/root/./..");
+			Test ("L20",  "c:/../");
+			Test ("L21",  "c:/..");
+			Test ("L22",  "c:/./");
+			Test ("L23",  "c:/.");
+			Test ("L24",  "c:/");
+			Test ("L25",  "/..");
+			Test ("L26",  "/.");
+			Test ("L27", "c:/windows//dir");
+			Test ("L28", "/root//dir");
+			Test ("L29", "/root/.              /");
+			Test ("L30", "/root/..             /");
+			Test ("L31", "/root/      .              /");
+			Test ("L32", "/root/      ..             /");
+			Test ("L33", "/root/			
+	  .						   /");
+			Test ("L34", "/root/			
+		 ..	  			   /");
+			Test ("L35", "/root/.			
+		/");
+			Test ("L36", "/root/..\t\t\t/");
+			Test ("L37", "/.//");
+			// Test ("L38", "/  /"); Exception : The UNC 
+path should be of the form \\server\share.
+			// Test ("L39", " "); Exception : The path 
+is not of a legal form.
+			// Test ("L40", "  "); Exception : The path 
+is not of a legal form.
+			// Test ("L38", "//"); Exception : The UNC 
+path should be of the form \\server\share.
+
+			System.Console.WriteLine ();
+		}
+	}
+}
+>>> EOT >>>