Bläddra i källkod

2005-07-29 Atsushi Enomoto <[email protected]>

	* XslFunctions.cs : XslTransform recovers from errors on document
	  resolution. Fixed bug #75663.

	* XslTransformTests.cs : added testcase for bug #75663.


svn path=/trunk/mcs/; revision=47843
Atsushi Eno 20 år sedan
förälder
incheckning
f2134e09c2

+ 5 - 0
mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog

@@ -1,3 +1,8 @@
+2005-07-29  Atsushi Enomoto  <[email protected]>
+
+	* XslFunctions.cs : XslTransform recovers from errors on document
+	  resolution. Fixed bug #75663.
+
 2005-06-06  Atsushi Enomoto  <[email protected]>
 
 	* HtmlEmitter.cs : Boolean attribute values should be omitted, but

+ 30 - 20
mcs/class/System.XML/Mono.Xml.Xsl/XslFunctions.cs

@@ -262,35 +262,45 @@ namespace Mono.Xml.Xsl
 		XPathNodeIterator GetDocument (XsltCompiledContext xsltContext, XPathNodeIterator itr, string baseUri)
 		{
 			ArrayList list = new ArrayList ();
-			Hashtable got = new Hashtable ();
+			try {
+				Hashtable got = new Hashtable ();
 			
-			while (itr.MoveNext()) {
-				Uri uri = Resolve (itr.Current.Value, baseUri != null ? baseUri : /*itr.Current.BaseURI*/doc.BaseURI, xsltContext.Processor);
-				if (!got.ContainsKey (uri)) {
-					got.Add (uri, null);
-					if (uri != null && uri.ToString () == "") {
-						XPathNavigator n = doc.Clone ();
-						n.MoveToRoot ();
-						list.Add (n);
-					} else
-						list.Add (xsltContext.Processor.GetDocument (uri));
+				while (itr.MoveNext()) {
+					Uri uri = Resolve (itr.Current.Value, baseUri != null ? baseUri : /*itr.Current.BaseURI*/doc.BaseURI, xsltContext.Processor);
+					if (!got.ContainsKey (uri)) {
+						got.Add (uri, null);
+						if (uri != null && uri.ToString () == "") {
+							XPathNavigator n = doc.Clone ();
+							n.MoveToRoot ();
+							list.Add (n);
+						} else
+							list.Add (xsltContext.Processor.GetDocument (uri));
+					}
 				}
+			} catch (Exception) {
+				// Error recovery.
+				// See http://www.w3.org/TR/xslt#document and
+				// bug #75663.
+				list.Clear ();
 			}
-			
 			return new ListIterator (list, xsltContext);
 		}
 	
 		XPathNodeIterator GetDocument (XsltCompiledContext xsltContext, string arg0, string baseUri)
 		{
-			Uri uri = Resolve (arg0, baseUri != null ? baseUri : doc.BaseURI, xsltContext.Processor);
-			XPathNavigator n;
-			if (uri != null && uri.ToString () == "") {
-				n = doc.Clone ();
-				n.MoveToRoot ();
-			} else
-				n = xsltContext.Processor.GetDocument (uri);
+			try {
+				Uri uri = Resolve (arg0, baseUri != null ? baseUri : doc.BaseURI, xsltContext.Processor);
+				XPathNavigator n;
+				if (uri != null && uri.ToString () == "") {
+					n = doc.Clone ();
+					n.MoveToRoot ();
+				} else
+					n = xsltContext.Processor.GetDocument (uri);
 			
-			return new SelfIterator (n, xsltContext);
+				return new SelfIterator (n, xsltContext);
+			} catch (Exception) {
+				return new ListIterator (new ArrayList (), xsltContext);
+			}
 		}
 
 		public override string ToString ()

+ 4 - 0
mcs/class/System.XML/Test/System.Xml.Xsl/ChangeLog

@@ -1,3 +1,7 @@
+2005-07-29  Atsushi Enomoto  <[email protected]>
+
+	* XslTransformTests.cs : added testcase for bug #75663.
+
 2005-05-07  Atsushi Enomoto  <[email protected]>
 
 	* MSXslScriptTests.cs : added testcase for bug #74859.

+ 21 - 0
mcs/class/System.XML/Test/System.Xml.Xsl/XslTransformTests.cs

@@ -251,5 +251,26 @@ namespace MonoTests.System.Xml.Xsl
 			t.Transform (doc, null, TextWriter.Null, null);
 			return wr;
 		}
+
+		[Test]
+		// bug #75663.
+		public void ErrorOnDocumentResolution ()
+		{
+			// XslTransform recovers from errors on document resolution.
+			string xslText = @"<xsl:stylesheet
+				xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
+				version='1.0'>
+				<xsl:variable name='n'
+					select='document(""notexist.xml"")' />
+				<xsl:template match='/'>xx</xsl:template>
+				</xsl:stylesheet>";
+			string xmlText = @"<root />";
+			XslTransform transform = new XslTransform ();
+			XPathDocument doc = new XPathDocument (
+				new XmlTextReader ("a.xsl", new StringReader (xslText)));
+			transform.Load (doc);
+			XPathDocument xmlDocument = new XPathDocument (new StringReader (xmlText));
+			transform.Transform (xmlDocument, null, TextWriter.Null);
+		}
 	}
 }