Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAtsushi Eno <atsushieno@gmail.com>2003-08-10 11:20:07 +0400
committerAtsushi Eno <atsushieno@gmail.com>2003-08-10 11:20:07 +0400
commitcd0ee00b63e70ea4baa095a1bf600537e71daf2b (patch)
tree811f7bc65bb029301c20731e1d98ae93628de1ce /mcs/class/System.XML/System.Xml/DTDObjectModel.cs
parent702703d7a0f81e4f4ebc962d132338ba921513b3 (diff)
2003-08-10 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
* DTDObjectModel.cs : added XmlResolver related members. Added invalid entity recursion logic. Added encodingdecl check on textdecl. * DTDValidatingReader.cs : It now implements IHasXmlParserContext. * XmlChar.cs : IsPubidChar() should not allow TAB(&#9;). * XmlDocumentType.cs : 1) internal CreateDocumentType() was now changed to receive DTDObjectModel to support other than XmlTextReader. 2) Most of its public member is now based on DTDObjectModel. * XmlDocument.cs : 1) Synchronous change with XmlDocumentType. 2) ReadNode() now considers XmlParserContext's DTDObjectModel for other than XmlTextReader (such as XmlValidatingReader). * XmlNode.cs : code cleanup only. * XmlParserInput.cs : added HasPEBuffer, used to check illegal nesting. * XmlTextReader.cs : 1) Illegal entity reference check logic was moved from ReadContent() to SetEntityReferenceProperties(). 2) Indentation change on ReadEntityReference(). 3) ReadAttribute() now checks reference to external entity reference. 4) Added textdecl encoding check. 5) DTDObjectModel fields are now set correctly. 6) added PERef markup nest check. 7) If PEDecl was not found, it might be WFC violation, not only be VC violation. 8) ReadEntityDecl() now receives its declared entity itself, and this method checks IsInternalSubset. * XmlValidatingReader.cs : 1) Added GetInternalPerserContext(). 2) ValidationType.None should be the same as Auto, not DTD (in the future it should keep xml schema's default values). Pending Stuff in XmlTextReader which breaks some NUnit tests; 1) SetEntityReferenceProperies() has check for illegal references. 2) ReadAttribute(bool) has similar check for illegal references. svn path=/trunk/mcs/; revision=17218
Diffstat (limited to 'mcs/class/System.XML/System.Xml/DTDObjectModel.cs')
-rw-r--r--mcs/class/System.XML/System.Xml/DTDObjectModel.cs90
1 files changed, 82 insertions, 8 deletions
diff --git a/mcs/class/System.XML/System.Xml/DTDObjectModel.cs b/mcs/class/System.XML/System.Xml/DTDObjectModel.cs
index 0752f3d4fd8..1d0419cad4c 100644
--- a/mcs/class/System.XML/System.Xml/DTDObjectModel.cs
+++ b/mcs/class/System.XML/System.Xml/DTDObjectModel.cs
@@ -8,6 +8,7 @@
//
using System;
using System.Collections;
+using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Text;
@@ -25,6 +26,7 @@ namespace Mono.Xml
DTDEntityDeclarationCollection entityDecls;
DTDNotationDeclarationCollection notationDecls;
ArrayList validationErrors;
+ XmlResolver resolver;
public DTDObjectModel ()
{
@@ -55,6 +57,14 @@ namespace Mono.Xml
return decl.EntityValue;
}
+ internal XmlResolver Resolver {
+ get { return resolver; }
+ }
+
+ public XmlResolver XmlResolver {
+ set { resolver = value; }
+ }
+
private DTDAutomataFactory factory;
public DTDAutomataFactory Factory {
get { return factory; }
@@ -396,6 +406,8 @@ namespace Mono.Xml
{
private DTDObjectModel root;
public string BaseURI;
+ public int LineNumber;
+ public int LinePosition;
internal void SetRoot (DTDObjectModel root)
{
@@ -605,21 +617,75 @@ namespace Mono.Xml
public string NotationName;
public string LiteralEntityValue;
public bool IsInternalSubset;
+ public StringCollection ReferencingEntities = new StringCollection ();
+ bool scanned;
+ bool recursed;
public string EntityValue {
get {
if (entityValue == null) {
- if (SystemId == null)
+ if (NotationName != null)
+ entityValue = "";
+ else if (SystemId == null)
entityValue = LiteralEntityValue;
else {
// FIXME: should use specified XmlUrlResolver.
- entityValue = ResolveExternalEntity (new XmlUrlResolver ());
+ entityValue = ResolveExternalEntity (Root.Resolver);
}
+ // Check illegal recursion.
+ ScanEntityValue (new StringCollection ());
}
return entityValue;
}
}
+ public void ScanEntityValue (StringCollection refs)
+ {
+ // To modify this code, beware nesting between this and EntityValue.
+ string value = EntityValue;
+
+ if (recursed)
+ throw new XmlException ("Entity recursion was found.");
+ recursed = true;
+
+ if (scanned) {
+ foreach (string referenced in refs)
+ if (this.ReferencingEntities.Contains (referenced))
+ throw new XmlException (String.Format (
+ "Nested entity was found between {0} and {1}",
+ referenced, Name));
+ recursed = false;
+ return;
+ }
+
+ int len = value.Length;
+ int start = 0;
+ for (int i=0; i<len; i++) {
+ switch (value [i]) {
+ case '&':
+ start = i+1;
+ break;
+ case ';':
+ if (start == 0)
+ break;
+ string name = value.Substring (start, i - start);
+ this.ReferencingEntities.Add (name);
+ DTDEntityDeclaration decl = Root.EntityDecls [name];
+ if (decl != null) {
+ refs.Add (Name);
+ decl.ScanEntityValue (refs);
+ foreach (string str in decl.ReferencingEntities)
+ ReferencingEntities.Add (str);
+ refs.Remove (Name);
+ }
+ start = 0;
+ break;
+ }
+ }
+ scanned = true;
+ recursed = false;
+ }
+
private string ResolveExternalEntity (XmlResolver resolver)
{
if (resolver == null)
@@ -637,14 +703,16 @@ namespace Mono.Xml
bool checkTextDecl = true;
while (reader.Peek () != -1) {
- sb.Append (reader.Read ());
+ sb.Append ((char) reader.Read ());
if (checkTextDecl && sb.Length == 6) {
if (sb.ToString () == "<?xml ") {
// Skip Text declaration.
sb.Length = 0;
StringBuilder textdecl = new StringBuilder ();
- while (reader.Peek () == '>' || reader.Peek () == -1)
- textdecl.Append (reader.Read ());
+ while (reader.Peek () != '>' && reader.Peek () != -1)
+ textdecl.Append ((char) reader.Read ());
+ if (textdecl.ToString ().IndexOf ("encoding") < 0)
+ throw new XmlException ("Text declaration must have encoding specification: " + BaseURI);
if (textdecl.ToString ().IndexOf ("standalone") >= 0)
throw new XmlException ("Text declaration cannot have standalone declaration: " + BaseURI);
}
@@ -711,11 +779,17 @@ namespace Mono.Xml
string absPath = absUri.ToString ();
try {
- TextReader tw = new XmlStreamReader (absUri.ToString (), false, resolver, BaseURI);
+ XmlStreamReader tw = new XmlStreamReader (absUri.ToString (), false, resolver, BaseURI);
string s = tw.ReadToEnd ();
if (s.StartsWith ("<?xml")) {
- int end = s.IndexOf (">" + 1);
- if (s.IndexOf ("standal0ne", end) >= 0)
+ int end = s.IndexOf (">") + 1;
+ if (end < 0)
+ throw new XmlException (this as IXmlLineInfo,
+ "Inconsistent text declaration markup.");
+ if (s.IndexOf ("encoding", 0, end) < 0)
+ throw new XmlException (this as IXmlLineInfo,
+ "Text declaration must not omit encoding specification.");
+ if (s.IndexOf ("standalone", 0, end) >= 0)
throw new XmlException (this as IXmlLineInfo,
"Text declaration cannot have standalone declaration.");
resolvedValue = s.Substring (end);