[Mono-devel-list] Bug: XmlParserContext BaseURI is null

Joshua Tauberer tauberer at for.net
Tue Dec 21 10:14:15 EST 2004


Atsushi,

After updating to the latest and greatest development RPMs of Mono I 
found a bug in XmlParserContext.  BaseURI is returned as null sometimes, 
which it should never be.  (If there's no URI, it should be the empty 
string.)

This test produces the problem:

using System;
using System.IO;
using System.Xml;

public class Test {
   public static void Main(string[] args) {
     string baseuri = new XmlTextReader(
	  new StringReader("<xml/>")).BaseURI;
     Console.WriteLine(baseuri == null ? "It's null."
	  : "It's not null.");
   }
}

I don't know where a fix would be appropriate.  There seem to be a few 
issues.  1) XmlParserContext can be initialized with a null BaseURI 
through its many constructors.  2)  When the XmlTextReader doesn't know 
about a URI, it doesn't set parserContext.BaseURI, leaving it at null.

(Also, when XmlTextReader encounters an xml:base attribute (I didn't 
even know those existed until now), and if an XmlResolver is set, the 
reader does this:
   parserContext.BaseURI = resolver.ResolveUri (new Uri (BaseURI), 
value).ToString ();
ResolveUri is allowed to return null, so this could throw a 
NullReferenceException.)

Initializing the parser context with "" instead of null fixes the test case.

Thanks for looking at this, as always.

-- 
- Joshua Tauberer

http://taubz.for.net

** Nothing Unreal Exists **





More information about the Mono-devel-list mailing list