2007-04-16 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Mon, 16 Apr 2007 08:37:02 +0000 (08:37 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Mon, 16 Apr 2007 08:37:02 +0000 (08:37 -0000)
* Uri.cs : in Uri(baseUri,relativeUri,noEscape), relativeUri could
  contain a URI scheme. In such cases the relativeUri could be still
  relative (i.e. not always equivalent to absolute). Fixed bug #81382.

* UriTest.cs : added relative .ctor() test where the relativeUris
  contain URI schemes.

svn path=/trunk/mcs/; revision=75743

mcs/class/System/System/ChangeLog
mcs/class/System/System/Uri.cs
mcs/class/System/Test/System/ChangeLog
mcs/class/System/Test/System/UriTest.cs

index 0b8fee43b693f56e39a8408f4439b89f162a392b..b447de366a78fcb29709a303293284aab47f8e64 100644 (file)
@@ -1,3 +1,9 @@
+2007-04-16  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * Uri.cs : in Uri(baseUri,relativeUri,noEscape), relativeUri could
+         contain a URI scheme. In such cases the relativeUri could be still
+         relative (i.e. not always equivalent to absolute). Fixed bug #81382.
+
 2007-03-05  Peter Dettman  <peter.dettman@iinet.net.au>
 
        * Uri.cs: This patch straightens out Equals/GetHashCode for the
index 18110dc023399e1a13b255112149527cf3516259..0d11f2feee3b13fa677c2a2e7c1b6aca3d5dd111 100644 (file)
@@ -218,14 +218,28 @@ namespace System {
                                // pos2 < 0 ... e.g. mailto
                                // pos2 > pos ... to block ':' in query part
                                if (pos2 > pos || pos2 < 0) {
-                                       // equivalent to new Uri (relativeUri, dontEscape)
-                                       source = relativeUri;
+                                       // in some cases, it is equivanent to new Uri (relativeUri, dontEscape):
+                                       // 1) when the URI scheme in the 
+                                       // relative path is different from that
+                                       // of the baseUri, or
+                                       // 2) the URI scheme is non-standard
+                                       // ones (non-standard URIs are always
+                                       // treated as absolute here), or
+                                       // 3) the relative URI path is absolute.
+                                       if (String.CompareOrdinal (baseUri.Scheme, 0, relativeUri, 0, pos) != 0 ||
+                                           !IsPredefinedScheme (baseUri.Scheme) ||
+                                           relativeUri.Length > pos + 1 &&
+                                           relativeUri [pos + 1] == '/') {
+                                               source = relativeUri;
 #if NET_2_0
-                                       ParseUri ();
+                                               ParseUri ();
 #else
-                                       Parse ();
+                                               Parse ();
 #endif
-                                       return;
+                                               return;
+                                       }
+                                       else
+                                               relativeUri = relativeUri.Substring (pos + 1);
                                }
                        }
 
index 495621e5b639a5d815130b7f4112005827b7f733..ecc9d03c33c93075b2062995a11b48a1b5094147 100644 (file)
@@ -1,3 +1,8 @@
+2007-04-16  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * UriTest.cs : added relative .ctor() test where the relativeUris
+         contain URI schemes.
+
 2007-01-25  Ilya Kharmatsky  <ilyak -at- mainsoft.com>
 
        * UriTypeConverterTest.cs: Added 'Ignore' attributes, 
index b7f5fdbde2fd3bde2094ab73c43f88f6227d1f5c..b9df86a16abbeb755f9233f2d687edca2ebf40ef 100644 (file)
@@ -1246,6 +1246,24 @@ namespace MonoTests.System
 #endif
                }
 
+               [Test]
+               public void RelativeUri2 ()
+               {
+                       AssertEquals ("#1", "hoge:ext", new Uri (new Uri ("hoge:foo:bar:baz"), "hoge:ext").ToString ());
+                       if (isWin32) {
+                               AssertEquals ("#2-w", "file:///d:/myhost/ext", new Uri (new Uri ("file:///c:/localhost/bar"), "file:///d:/myhost/ext").ToString ());
+                               AssertEquals ("#3-w", "file:///c:/localhost/myhost/ext", new Uri (new Uri ("file:///c:/localhost/bar"), "file:myhost/ext").ToString ());
+                               AssertEquals ("#4-w", "uuid:ext", new Uri (new Uri ("file:///c:/localhost/bar"), "uuid:ext").ToString ());
+                               AssertEquals ("#5-w", "file:///c:/localhost/ext", new Uri (new Uri ("file:///c:/localhost/bar"), "file:./ext").ToString ());
+                       } else {
+                               AssertEquals ("#2-u", "file:///d/myhost/ext", new Uri (new Uri ("file:///c/localhost/bar"), "file:///d/myhost/ext").ToString ());
+                               AssertEquals ("#3-u", "file:///c/localhost/myhost/ext", new Uri (new Uri ("file:///c/localhost/bar"), "file:myhost/ext").ToString ());
+                               AssertEquals ("#4-u", "uuid:ext", new Uri (new Uri ("file:///c/localhost/bar"), "uuid:ext").ToString ());
+                               AssertEquals ("#5-u", "file:///c/localhost/ext", new Uri (new Uri ("file:///c/localhost/bar"), "file:./ext").ToString ());
+                       }
+                       AssertEquals ("#6", "http://localhost/ext", new Uri (new Uri ("http://localhost/bar"), "http:./ext").ToString ());
+               }
+
                [Test]
                public void ToStringTest()
                {