// It returns whether the entity contains references to external entities. public void ScanEntityValue(ArrayList refs) { // To modify this code, beware nesting between this and EntityValue. string value = EntityValue; if (this.SystemId != null) { hasExternalReference = true; } if (recursed) { throw NotWFError("Entity recursion was found."); } recursed = true; if (scanned) { foreach (string referenced in refs) { if (this.ReferencingEntities.Contains(referenced)) { throw NotWFError(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); if (name.Length == 0) { throw NotWFError("Entity reference name is missing."); } if (name [0] == '#') { break; // character reference } if (XmlChar.GetPredefinedEntity(name) >= 0) { break; // predefined reference } this.ReferencingEntities.Add(name); DTDEntityDeclaration decl = Root.EntityDecls [name]; if (decl != null) { if (decl.SystemId != null) { hasExternalReference = true; } refs.Add(Name); decl.ScanEntityValue(refs); foreach (string str in decl.ReferencingEntities) { ReferencingEntities.Add(str); } refs.Remove(Name); value = value.Remove(start - 1, name.Length + 2); value = value.Insert(start - 1, decl.EntityValue); i -= name.Length + 1; // not +2, because of immediate i++ . len = value.Length; } start = 0; break; } } if (start != 0) #if NET_2_1 { Root.AddError(new XmlSchemaException(this, this.BaseURI, "Invalid reference character '&' is specified.")); } #else { Root.AddError(new XmlSchemaException("Invalid reference character '&' is specified.", this.LineNumber, this.LinePosition, null, this.BaseURI, null)); } #endif scanned = true; recursed = false; }
public void ScanEntityValue(ArrayList refs) { string text = this.EntityValue; if (base.SystemId != null) { this.hasExternalReference = true; } if (this.recursed) { throw base.NotWFError("Entity recursion was found."); } this.recursed = true; if (this.scanned) { foreach (object obj in refs) { string text2 = (string)obj; if (this.ReferencingEntities.Contains(text2)) { throw base.NotWFError(string.Format("Nested entity was found between {0} and {1}", text2, base.Name)); } } this.recursed = false; return; } int length = text.Length; int num = 0; for (int i = 0; i < length; i++) { char c = text[i]; if (c != '&') { if (c == ';') { if (num != 0) { string text3 = text.Substring(num, i - num); if (text3.Length == 0) { throw base.NotWFError("Entity reference name is missing."); } if (text3[0] != '#') { if (XmlChar.GetPredefinedEntity(text3) < 0) { this.ReferencingEntities.Add(text3); DTDEntityDeclaration dtdentityDeclaration = base.Root.EntityDecls[text3]; if (dtdentityDeclaration != null) { if (dtdentityDeclaration.SystemId != null) { this.hasExternalReference = true; } refs.Add(base.Name); dtdentityDeclaration.ScanEntityValue(refs); foreach (object obj2 in dtdentityDeclaration.ReferencingEntities) { string value = (string)obj2; this.ReferencingEntities.Add(value); } refs.Remove(base.Name); text = text.Remove(num - 1, text3.Length + 2); text = text.Insert(num - 1, dtdentityDeclaration.EntityValue); i -= text3.Length + 1; length = text.Length; } num = 0; } } } } } else { num = i + 1; } } if (num != 0) { base.Root.AddError(new XmlException(this, this.BaseURI, "Invalid reference character '&' is specified.")); } this.scanned = true; this.recursed = false; }