Fix bug 998 - in XmlResolver.ResolveUri(), make some policy change on "how to determi...
authorAtsushi Eno <atsushi@ximian.com>
Thu, 19 Jan 2012 11:45:42 +0000 (20:45 +0900)
committerAtsushi Eno <atsushi@ximian.com>
Thu, 19 Jan 2012 11:45:42 +0000 (20:45 +0900)
It's a bit difficult decision, as the "relative URI" could be any path string
that contain colons as a *valid* path (especially on *nix land).
We historically did allow such string that contain "http:" etc. as to be
treated as absolute (which historically worked long time).
But this test case uncovered possible other cases.
Hopefully this does not bring issues that is pretty much anticipated. Such
issues could also happen in older code anyways.

mcs/class/System.XML/System.Xml/XmlResolver.cs
mcs/class/System.XML/Test/System.Xml/XmlUrlResolverTests.cs

index 0cf9f3172593eaead0697d0b073cef54db557841..356873a61e207da9fa661e916df5ac37408e3624 100644 (file)
@@ -57,10 +57,8 @@ namespace System.Xml
                                return new Uri (relativeUri, UriKind.RelativeOrAbsolute);
 #else
                                // Don't ignore such case that relativeUri is in fact absolute uri (e.g. ResolveUri (null, "http://foo.com")).
-                               if (relativeUri.StartsWith ("http:") ||
-                                       relativeUri.StartsWith ("https:") ||
-                                       relativeUri.StartsWith ("ftp:") ||
-                                       relativeUri.StartsWith ("file:"))
+                               int idx = relativeUri.IndexOf (':');
+                               if (idx > 0 && Uri.CheckSchemeName (relativeUri.Substring (0, idx)))
                                        return new Uri (relativeUri);
                                else
                                        return new Uri (Path.GetFullPath (relativeUri));
index 31d720ccfbc9256be52519154eac94f960d9429c..09ac79a423fad90abffb229addeae982aecf97f8 100644 (file)
@@ -88,5 +88,15 @@ namespace MonoTests.System.Xml
                {\r
                        resolver.GetEntity (new Uri ("http://www.go-mono.com/"), null, typeof (File));\r
                }\r
+\r
+               [Test] // bug #998\r
+               public void NullAbsoluteUriWithCustomSchemedRelativeUri ()\r
+               {\r
+                       XmlResolver res = new XmlUrlResolver ();\r
+                       var uri = res.ResolveUri (null, "view:Standard.xslt");\r
+                       Assert.AreEqual ("view", uri.Scheme, "#1");\r
+                       Assert.AreEqual ("Standard.xslt", uri.AbsolutePath, "#2");\r
+                       Assert.AreEqual ("view:Standard.xslt", uri.AbsoluteUri, "#2");\r
+               }\r
        }\r
 }\r