Merge pull request #1262 from esdrubal/uriserializationinfo
authorMarek Safar <marek.safar@gmail.com>
Mon, 8 Sep 2014 14:40:33 +0000 (05:40 -0900)
committerMarek Safar <marek.safar@gmail.com>
Mon, 8 Sep 2014 14:40:33 +0000 (05:40 -0900)
Added support for UriComponents.SerializationInfoString.

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

index 105004e39c8b910fbbca5489174f90121a328528..fb9c14eead150e43c8385ea23551dc577d82fc1b 100644 (file)
@@ -1725,7 +1725,7 @@ namespace System {
                private UriParser Parser {
                        get {
                                if (parser == null) {
-                                       parser = UriParser.GetParser (Scheme);
+                                       parser = UriParser.GetParser (scheme);
                                        // no specific parser ? then use a default one
                                        if (parser == null)
                                                parser = new DefaultUriParser ("*");
@@ -1737,6 +1737,9 @@ namespace System {
 
                public string GetComponents (UriComponents components, UriFormat format)
                {
+                       if ((components & UriComponents.SerializationInfoString) == 0)
+                               EnsureAbsoluteUri ();
+
                        return Parser.GetComponents (this, components, format);
                }
 
index 8abfdc9b359b0e0c3893a080fe2119032efbb6f4..5eda9aadc17853ab9f3a9f4d89e9b80407f93e6b 100644 (file)
@@ -50,6 +50,16 @@ namespace System {
                        if ((format < UriFormat.UriEscaped) || (format > UriFormat.SafeUnescaped))
                                throw new ArgumentOutOfRangeException ("format");
 
+                       if ((components & UriComponents.SerializationInfoString) != 0) {
+                               if (components != UriComponents.SerializationInfoString)
+                                       throw new ArgumentOutOfRangeException ("components", "UriComponents.SerializationInfoString must not be combined with other UriComponents.");
+
+                               if (!uri.IsAbsoluteUri)
+                                       return UriHelper.FormatRelative (uri.OriginalString, "", format);
+
+                               components |= UriComponents.AbsoluteUri;
+                       }
+
                        return GetComponentsHelper (uri, components, format);
                }
 
index f0a67b7a7cd700cba440bd54e5f757874df0bd66..b3b33170c584a1912bc36937b57c60517dc91617 100644 (file)
@@ -1951,6 +1951,23 @@ namespace MonoTests.System
                        Assert.IsTrue (Uri.TryCreate (mainUri, uriPath, out result), "#1");
                        Assert.AreEqual ("http://www.imdb.com/title/tt0106521", result.ToString (), "#2");
                }
+
+               [Test]
+               public void GetSerializationInfoStringOnRelativeUri ()
+               {
+                       var uri = new Uri ("/relative/path", UriKind.Relative);
+                       var result = uri.GetComponents (UriComponents.SerializationInfoString, UriFormat.UriEscaped);
+
+                       Assert.AreEqual (uri.OriginalString, result);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentOutOfRangeException))]
+               public void GetSerializationInfoStringException ()
+               {
+                       var uri = new Uri ("/relative/path", UriKind.Relative);
+                       uri.GetComponents (UriComponents.SerializationInfoString  | UriComponents.Host, UriFormat.UriEscaped);
+               }
        }
 
        // Tests non default IriParsing