Bläddra i källkod

2005-06-14 Atsushi Enomoto <[email protected]>

	* DTDValidatingReader.cs : further text node fixes.
	  - Cut out validation code from Text node case.
	  - Now it does not use error-prone case transition but uses 
	    DocumentFragment 'vacant room' and fixed incorrect transition from
	    whitespace to text.
	  - CDATA should be validated the same as Text is.


svn path=/trunk/mcs/; revision=45935
Atsushi Eno 20 år sedan
förälder
incheckning
0d14407e85

+ 9 - 0
mcs/class/System.XML/System.Xml/ChangeLog

@@ -1,3 +1,12 @@
+2005-06-14  Atsushi Enomoto <[email protected]>
+
+	* DTDValidatingReader.cs : further text node fixes.
+	  - Cut out validation code from Text node case.
+	  - Now it does not use error-prone case transition but uses 
+	    DocumentFragment 'vacant room' and fixed incorrect transition from
+	    whitespace to text.
+	  - CDATA should be validated the same as Text is.
+
 2005-06-14  Atsushi Enomoto <[email protected]>
 
 	* DTDValidatingReader.cs : whitespace nodes were incorrectly rejected

+ 32 - 17
mcs/class/System.XML/System.Xml/DTDValidatingReader.cs

@@ -569,6 +569,11 @@ namespace Mono.Xml
 				break;
 
 			case XmlNodeType.CDATA:
+				isSignificantWhitespace = isWhitespace = false;
+				isText = true;
+
+				ValidateText ();
+
 				if (currentTextValue != null) {
 					currentTextValue = constructingTextValue;
 					constructingTextValue = null;
@@ -580,26 +585,19 @@ namespace Mono.Xml
 					isSignificantWhitespace = true;
 				isWhitespace = false;
 				dontResetTextType = true;
-				goto case XmlNodeType.Text;
+				goto case XmlNodeType.DocumentFragment;
 			case XmlNodeType.Text:
-				bool wasWhitespace = isWhitespace;
+				isWhitespace = isSignificantWhitespace = false;
 				isText = true;
-				if (!dontResetTextType) {
-					isWhitespace = isSignificantWhitespace = false;
-				}
-				// If no schema specification, then skip validation.
-				if (currentAutomata == null)
+				goto case XmlNodeType.DocumentFragment;
+			case XmlNodeType.DocumentFragment:
+				// it should not happen, but in case if
+				// XmlReader really returns it, just ignore.
+				if (reader.NodeType == XmlNodeType.DocumentFragment)
 					break;
 
-				if (elementStack.Count > 0)
-					elem = dtd.ElementDecls [elementStack.Peek () as string];
-				// Here element should have been already validated, so
-				// if no matching declaration is found, simply ignore.
-				if (elem != null && !elem.IsMixedContent && !elem.IsAny && !wasWhitespace) {
-					HandleError (String.Format ("Current element {0} does not allow character data content.", elementStack.Peek () as string),
-						XmlSeverityType.Error);
-					currentAutomata = previousAutomata;
-				}
+				ValidateText ();
+
 				if (entityReaderStack.Count > 0 && validatingReader.EntityHandling == EntityHandling.ExpandEntities) {
 					constructingTextValue += reader.Value;
 					return ReadContent ();
@@ -608,7 +606,7 @@ namespace Mono.Xml
 			case XmlNodeType.Whitespace:
 				if (!isText && !isSignificantWhitespace)
 					isWhitespace = true;
-				goto case XmlNodeType.Text;
+				goto case XmlNodeType.DocumentFragment;
 			case XmlNodeType.EntityReference:
 				if (validatingReader.EntityHandling == EntityHandling.ExpandEntities) {
 					ResolveEntity ();
@@ -624,6 +622,23 @@ namespace Mono.Xml
 			return true;
 		}
 
+		private void ValidateText ()
+		{
+			if (currentAutomata == null)
+				return;
+
+			DTDElementDeclaration elem = null;
+			if (elementStack.Count > 0)
+				elem = dtd.ElementDecls [elementStack.Peek () as string];
+			// Here element should have been already validated, so
+			// if no matching declaration is found, simply ignore.
+			if (elem != null && !elem.IsMixedContent && !elem.IsAny && !isWhitespace) {
+				HandleError (String.Format ("Current element {0} does not allow character data content.", elementStack.Peek () as string),
+					XmlSeverityType.Error);
+				currentAutomata = previousAutomata;
+			}
+		}
+
 		private void ValidateWhitespaceNode ()
 		{
 			// VC Standalone Document Declaration (2.9)