PhoenixmlDb.Core

SchemaPatternGuard

Bounds the regular expressions behind XSD pattern facets. System.Xml builds them with no match timeout of its own, so a pattern that backtracks catastrophically runs for as long as the value makes it, in a cast to a schema type, in validation, and while the schema compiles (which checks the schema's own enumeration, default and fixed values against its patterns).

#SchemaPatternGuard

Namespace: PhoenixmlDb.Core.Schema

Bounds the regular expressions behind XSD

pattern

facets. System.Xml builds them with no match timeout of its own, so a pattern that backtracks catastrophically runs for as long as the value makes it, in a cast to a schema type, in validation, and while the schema compiles (which checks the schema's own enumeration, default and fixed values against its patterns).

A compiled schema set keeps each type's patterns as Regex objects in a list that has no public accessor. SchemaPatternGuard.Bound replaces each with the same expression and a match timeout, which is the only way to reach the matches a validating reader makes: it sees a value and its type together, and nothing outside it does before the match runs.

That reads System.Xml's private state, so it fails closed: where the expected shape is missing and the schema set declares a pattern, SchemaPatternGuard.Bound throws rather than report a bound it did not apply.

#Methods

#Bound(Xml.Schema.XmlSchemaSet,TimeSpan)

Gives every pattern facet of a compiled schema set the match timeout

. Returns how many patterns the set's types carry.

Exceptions:

  • NotSupportedException — The set declares a pattern facet and none could be reached on this runtime.

#CheckSchemaLiterals(Xml.Schema.XmlSchemaSet,TimeSpan,Collections.Generic.HashSet<String>,Collections.Generic.HashSet<String>)

Runs every pattern facet of the set against every value the schemas themselves supply (other facets' values, defaults and fixed values), each match under

, before the set is compiled. Compiling makes those matches with no timeout. Pairs already checked are remembered in

and

.

Exceptions:

#CompileWithCharacterLengths(Xml.Schema.XmlSchemaSet)

on a set that has just compiled, and the second compilation it asks for. Nothing happens for a set that did not compile, or that has no length facet left to change.

#CountCharactersInLengths(Xml.Schema.XmlSchemaSet)

Makes the length facets of the string types of a compiled schema set count characters as XML Schema does, by code point. System.Xml counts UTF-16 units, so

maxLength="1"

refused one character outside the Basic Multilingual Plane and

minLength="2"

accepted it. Call it after the set has compiled, so that the rules that relate the length facets of a type to those of its base have been checked on the facets as written. When it returns true it has changed the set, which must be compiled again (

each schema, then compile).

The count is inside System.Xml and cannot be changed, so each

length

,

minLength

and

maxLength

of a type derived from xs:string or xs:anyURI is taken out and a pattern put in its place that asks for the same number of characters. The facets of a list type (a number of items) and of a binary type (a number of octets) are left alone. A value then fails as a pattern does;

gives the message of the facet back.

#CountsCharacters(Xml.Schema.XmlSchemaObject)

Whether the restriction is of a type whose length is a number of characters: an atomic type derived from xs:string or xs:anyURI.

#LengthPattern(Int32,Nullable<Int32>)

A pattern for a value of

to

characters. A value with no surrogate pair is counted by unit, which is the same number and far quicker; one with a pair is counted by code point.

#LengthRule(String)

The validation rule of the length facet a restored message names; null for any other message.

#MatchWholeCharacters(Xml.Schema.XmlSchemaSet)

Makes every pattern facet of a schema set that is not yet compiled count characters as XML Schema does, by code point, where System.Xml would count UTF-16 units: the pattern "." refused a value of one character outside the Basic Multilingual Plane, a negated class or category took it for two characters, and a category it belongs to did not match it. Call it before the set is compiled. A second call changes nothing.

#RestoreLengthMessage(String,Xml.Schema.XmlSchemaType)

The message of a value that failed validation, with the words of the length facet it broke where System.Xml reports the pattern that stands for the facet (

). Any other message is returned as it is.

Parameters:

  • message — The message of the validation event.

  • type — The type of the element or attribute the value belongs to; null when not known.

#RestoreLengthMessage(String,Xml.XmlReader,Xml.Schema.XmlSchemaException)

for a message raised while

validates: the type is that of what the event names, or of the element the reader is on, or of the attribute of it that the message names.

#ToNetPattern(String)

The .NET expression System.Xml builds for one pattern facet: anchored, grouped, with the XSD class escapes rewritten to the classes .NET keeps for them.

#WithWholeCharacters(String)

The pattern with every atom that stands for one character made to match one code point; see

.

The rewritten pattern is long (a category is hundreds of ranges above U+FFFF) and an alternation where there was a set, so it matches several times slower. Almost every value has no character above U+FFFF, and for such a value the pattern as written is right. So the result tests the value first, with one pass, and uses the pattern as written when it holds no pair. A pattern that itself holds a character above U+FFFF has no such form: as written, .NET reads it as two units.

#Fields

Name Description
Rewritten Every schema object reachable from the set: the schema documents with what they include, import and redefine, and — once compiled — the types, elements and attributes the compilation resolved, anonymous ones included.