Summary
=======

System.Xml.Schema validation incorrectly allows ^ and $ as line anchors.
However, $ is an invalid atom in the XML Schema Datatypes specification and
^ is only allowed as part of a negative character group.

Since (according to the ROTOR sources) System.Xml.Schema simply delegates
all processing to RegEx.IsMatch() [see
newxml\schema\datatypeimplementation.cs:182], it doesn't perform any checks
of the subset of allowable characters.

MSXML4 RTM also had this bug, but it was fixed with MSXML4 SP1.

Steps to reproduce
==================

Compile and run the following code. No validation errors are generated, even
though the pattern is invalid.


source.xml
----------

<xml>1234567890</xml>

schema.xsd
----------

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
        <xsd:element name="xml" type="document"/>
        <xsd:simpleType name="document">
                <xsd:restriction base="xsd:string">
                        <xsd:pattern value="^1234567890$"/>
                </xsd:restriction>
        </xsd:simpleType>
</xsd:schema>

test.cs
-------

using System;
using System.Xml;
using System.Xml.Schema;

public class X {
  static void Main() {

        XmlReader oReader;


        oReader=new XmlTextReader("source.xml");
        XmlValidatingReader oValidator=new XmlValidatingReader(oReader);


        oValidator.Schemas.Add("", new XmlTextReader("schema.xsd"));

        // Set the validation event handler
        oValidator.ValidationEventHandler += new
ValidationEventHandler(ValidationCallBack);

        oValidator.ValidationType=ValidationType.Schema;

        // Read XML data
        while (oValidator.Read()){}

        oValidator.Close();
  }

  public static void ValidationCallBack (object sender, ValidationEventArgs
args) {
        Console.WriteLine("Validation error: {0}", args.Message );
        Console.WriteLine("Line {0}, Position {1}, Source {2}",
args.Exception.LineNumber,
                                                                                       
  args.Exception.LinePosition,
                                                                                       
  args.Exception.Source);
  }
}




Richard

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to