Author: miguel
Date: 2007-06-30 19:45:34 -0400 (Sat, 30 Jun 2007)
New Revision: 81132

Modified:
   trunk/mcs/class/System/System/ChangeLog
   trunk/mcs/class/System/System/Uri.cs
   trunk/mcs/class/System/Test/System/UriTest.cs
Log:
Surprisingly support for 2.0 Relative was not implemented nor tested.

2007-06-30  Miguel de Icaza  <[EMAIL PROTECTED]>

        * Uri.cs (GetLeftPart): If the URI is relative this method throws
        InvalidOperationException. 

        (ToString): do not use GetLeftPart here, instead escape the path. 

        (Parse): For relative uris, keep the string as the path.



Modified: trunk/mcs/class/System/System/ChangeLog
===================================================================
--- trunk/mcs/class/System/System/ChangeLog     2007-06-30 22:35:29 UTC (rev 
81131)
+++ trunk/mcs/class/System/System/ChangeLog     2007-06-30 23:45:34 UTC (rev 
81132)
@@ -1,3 +1,12 @@
+2007-06-30  Miguel de Icaza  <[EMAIL PROTECTED]>
+
+       * Uri.cs (GetLeftPart): If the URI is relative this method throws
+       InvalidOperationException. 
+
+       (ToString): do not use GetLeftPart here, instead escape the path. 
+
+       (Parse): For relative uris, keep the string as the path.
+
 2007-06-30  Gert Driesen  <[EMAIL PROTECTED]>
 
        * Uri.cs: Canonicalize is only obsolete from 2.0 onward. Fixed line

Modified: trunk/mcs/class/System/System/Uri.cs
===================================================================
--- trunk/mcs/class/System/System/Uri.cs        2007-06-30 22:35:29 UTC (rev 
81131)
+++ trunk/mcs/class/System/System/Uri.cs        2007-06-30 23:45:34 UTC (rev 
81132)
@@ -827,6 +827,7 @@
                
                public string GetLeftPart (UriPartial part) 
                {
+                       EnsureAbsoluteUri ();
                        int defaultPort;
                        switch (part) {                         
                        case UriPartial.Scheme : 
@@ -847,7 +848,7 @@
                                if ((port != -1) && (port != defaultPort))
                                        s.Append (':').Append (port);           
         
                                return s.ToString ();                           
-                       case UriPartial.Path :                  
+                       case UriPartial.Path :
                                StringBuilder sb = new StringBuilder ();
                                sb.Append (scheme);
                                sb.Append (GetOpaqueWiseSchemeDelimiter ());
@@ -1006,7 +1007,13 @@
                        if (cachedToString != null) 
                                return cachedToString;
 
-                       cachedToString = Unescape (GetLeftPart 
(UriPartial.Path), true);
+                       if (isAbsoluteUri)
+                               cachedToString = Unescape (GetLeftPart 
(UriPartial.Path), true);
+                       else {
+                               // Everything is contained in path in this 
case. 
+                               cachedToString = Unescape (path);
+                       }
+                       
                        if (query.Length > 0) {
                                string q = query [0] == '?' ? '?' + Unescape 
(query.Substring (1), true) : Unescape (query, true);
                                cachedToString += q;
@@ -1259,9 +1266,11 @@
                                        ParseAsUnixAbsoluteFilePath (uriString);
                                else if (uriString.Length >= 2 && uriString [0] 
== '\\' && uriString [1] == '\\')
                                        ParseAsWindowsUNC (uriString);
-                               else
+                               else {
                                        /* Relative path */
                                        isAbsoluteUri = false;
+                                       path = uriString;
+                               }
                                return;
                        } 
                        else if (pos == 1) {

Modified: trunk/mcs/class/System/Test/System/UriTest.cs
===================================================================
--- trunk/mcs/class/System/Test/System/UriTest.cs       2007-06-30 22:35:29 UTC 
(rev 81131)
+++ trunk/mcs/class/System/Test/System/UriTest.cs       2007-06-30 23:45:34 UTC 
(rev 81132)
@@ -1176,7 +1176,41 @@
                        Assert ("#5b", !uri3.Equals(uri4));
                }
 
+               [ExpectedException(typeof(InvalidOperationException))]
                [Test]
+               public void GetLeftPart_Partial1 ()
+               {
+                       Uri u = new Uri ("foo", UriKind.Relative);
+                       u.GetLeftPart (UriPartial.Scheme);
+               }
+
+               [ExpectedException(typeof(InvalidOperationException))]
+               [Test]
+               public void GetLeftPart_Partial2 ()
+               {
+                       Uri u = new Uri ("foo", UriKind.Relative);
+                       u.GetLeftPart (UriPartial.Authority);
+               }
+
+               [ExpectedException(typeof(InvalidOperationException))]
+               [Test]
+               public void GetLeftPart_Partial3 ()
+               {
+                       Uri u = new Uri ("foo", UriKind.Relative);
+                       u.GetLeftPart (UriPartial.Path);
+               }
+               
+               [Test]
+               public void TestPartialToString ()
+               {
+                       AssertEquals ("#1", new Uri ("foo", 
UriKind.Relative).ToString (), "foo");
+                       AssertEquals ("#2", new Uri ("foo#aa", 
UriKind.Relative).ToString (), "foo#aa");
+                       AssertEquals ("#3", new Uri ("foo?aa", 
UriKind.Relative).ToString (), "foo?aa");
+                       AssertEquals ("#4", new Uri ("foo#dingus?aa", 
UriKind.Relative).ToString (), "foo#dingus?aa");
+                       AssertEquals ("#4", new Uri ("foo?dingus#aa", 
UriKind.Relative).ToString (), "foo?dingus#aa");
+               }
+               
+               [Test]
                public void RelativeGetHashCodeTest()
                {
                        Uri uri1 = new Uri ("foo/bar", UriKind.Relative);

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

Reply via email to