Просмотр исходного кода

2003-07-27 Piers Haken <[email protected]>

	* Expression.cs:
	* DefaultContext.cs:
		catch FormatExceptions while parsing numbers

svn path=/trunk/mcs/; revision=16767
Piers Haken 22 лет назад
Родитель
Сommit
ae935bbac4

+ 6 - 0
mcs/class/System.XML/System.Xml.XPath/ChangeLog

@@ -1,3 +1,9 @@
+2003-07-27  Piers Haken	<[email protected]>
+
+	* Expression.cs:
+	* DefaultContext.cs:
+		catch FormatExceptions while parsing numbers
+
 2003-07-27  Piers Haken	<[email protected]>
 
 	* Expression.cs:

+ 11 - 2
mcs/class/System.XML/System.Xml.XPath/DefaultContext.cs

@@ -159,10 +159,19 @@ namespace System.Xml.XPath
 		{
 			if (arg == null)
 				throw new ArgumentNullException ();
+			if (arg is string)
+			{
+				try
+				{
+					return XmlConvert.ToDouble ((string) arg);	// TODO: spec? convert string to number
+				}
+				catch (System.FormatException)
+				{
+					return double.NaN;
+				}
+			}
 			if (arg is BaseIterator)
 				arg = ToString (arg);	// follow on
-			if (arg is string)
-				return XmlConvert.ToDouble ((string) arg);	// TODO: spec? convert string to number
 			if (arg is double)
 				return (double) arg;
 			if (arg is bool)

+ 2 - 2
mcs/class/System.XML/System.Xml.XPath/Expression.cs

@@ -331,9 +331,9 @@ namespace System.Xml.XPath
 				case XPathResultType.Boolean:
 					return Convert.ToDouble ((bool) result);
 				case XPathResultType.NodeSet:
-					return XmlConvert.ToDouble (EvaluateString (iter));
+					return XPathFunctions.ToNumber (EvaluateString (iter));
 				case XPathResultType.String:
-					return XmlConvert.ToDouble ((string) result);	// TODO: spec? convert string to number
+					return XPathFunctions.ToNumber ((string) result);	// TODO: spec? convert string to number
 				default:
 					throw new XPathException ("invalid node type"); // TODO: handle other types
 			}