From 82f61e9074d85129cf7d23c768af03149f0a2d74 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Thu, 19 Jan 2012 20:45:42 +0900 Subject: [PATCH] Fix bug 998 - in XmlResolver.ResolveUri(), make some policy change on "how to determine a string as an absolute URI. 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 | 6 ++---- .../System.XML/Test/System.Xml/XmlUrlResolverTests.cs | 10 ++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/mcs/class/System.XML/System.Xml/XmlResolver.cs b/mcs/class/System.XML/System.Xml/XmlResolver.cs index 0cf9f317259..356873a61e2 100644 --- a/mcs/class/System.XML/System.Xml/XmlResolver.cs +++ b/mcs/class/System.XML/System.Xml/XmlResolver.cs @@ -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)); diff --git a/mcs/class/System.XML/Test/System.Xml/XmlUrlResolverTests.cs b/mcs/class/System.XML/Test/System.Xml/XmlUrlResolverTests.cs index 31d720ccfbc..09ac79a423f 100644 --- a/mcs/class/System.XML/Test/System.Xml/XmlUrlResolverTests.cs +++ b/mcs/class/System.XML/Test/System.Xml/XmlUrlResolverTests.cs @@ -88,5 +88,15 @@ namespace MonoTests.System.Xml { resolver.GetEntity (new Uri ("http://www.go-mono.com/"), null, typeof (File)); } + + [Test] // bug #998 + public void NullAbsoluteUriWithCustomSchemedRelativeUri () + { + XmlResolver res = new XmlUrlResolver (); + var uri = res.ResolveUri (null, "view:Standard.xslt"); + Assert.AreEqual ("view", uri.Scheme, "#1"); + Assert.AreEqual ("Standard.xslt", uri.AbsolutePath, "#2"); + Assert.AreEqual ("view:Standard.xslt", uri.AbsoluteUri, "#2"); + } } } -- 2.25.1