sorry, I sent this earlier but forgot to mark as [PATCH]

Right now unix paths are being accepted as a valid absolute path, but in
ms.net the path "/test.aspx"  is relative

Theres no real way to differentiate between the web relative path and a unix
path so I suggest we do a check,
if UriKind.Relative is passed, allow /test.aspx as relative, otherwise
consider it absolute.

I've attached the patch for this and its test.

The other way would be to require unix paths to have file:// on them, but
then we'd break code like:  new Uri( System.IO.Path.GetFullPath
("test/test.aspx"))
Index: System/Uri.cs
===================================================================
--- System/Uri.cs       (revision 85855)
+++ System/Uri.cs       (working copy)
@@ -90,9 +90,11 @@
                private string cachedToString;
                private string cachedLocalPath;
                private int cachedHashCode;
-
+          
                private static readonly string hexUpperChars = "0123456789ABCDEF";
-
+#if NET_2_0       
+        private UriKind uriKind;
+#endif
                // Fields
 
                public static readonly string SchemeDelimiter = "://";
@@ -125,6 +127,7 @@
                public Uri (string uriString, UriKind uriKind)
                {
                        source = uriString;
+            this.uriKind = uriKind;
                        ParseUri ();
 
                        switch (uriKind) {
@@ -1263,7 +1266,11 @@
                                        + "determined.");
                        } else if (pos < 0) {
                                // It must be Unix file path or Windows UNC
+#if NET_2_0
+                               if (uriString [0] == '/' && uriKind != UriKind.Relative)
+#else                   
                                if (uriString [0] == '/')
+#endif
                                        ParseAsUnixAbsoluteFilePath (uriString);
                                else if ( uriString.Length >= 2 && uriString [0] == '\\' && uriString [1] == '\\')
                                        ParseAsWindowsUNC (uriString);


Index: Test/System/UriTest.cs
===================================================================
--- Test/System/UriTest.cs      (revision 85855)
+++ Test/System/UriTest.cs      (working copy)
@@ -1182,6 +1182,12 @@
                        Assert ("#5b", !uri3.Equals(uri4));
                }
 
+        [Test]
+        public void RootedRelativePath()
+        {
+            Uri uri1 = new Uri ("/test.aspx", UriKind.Relative);
+            Assert ("#1", uri1.IsAbsoluteUri == false);
+        }
                [ExpectedException(typeof(InvalidOperationException))]
                [Test]
                public void GetLeftPart_Partial1 ()


_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to