GNOME Bugzilla – Bug 512454
xmllint --relaxng validation fails incorrectly w/ --stream and validates w/o
Last modified: 2017-06-12 19:07:03 UTC
Please describe the problem: Relax NG validation in some cases fails when used with xmlReader API where it should not. It succeeds on the same input when using tree API. The three RNG files below and a test XML file demonstrate the problem. Steps to reproduce: 1. create files foo.rng, foo_1_1.rng, foo_1_2.rng and test.xml from the XML given int the "other information" section below 2. run xmllint --noout --relaxng foo.rng test.xml and see test4.xml validates 3. run xmllint --noout --stream --relaxng foo.rng test4.xml and see test4.xml:4: element foo: Relax-NG validity error : Element foo failed to validate attributes test4.xml:4: element foo: Relax-NG validity error : Invalid attribute version for element foo test4.xml fails to validate Actual results: 3. fails while 2. succeedes Expected results: both should succeed Does this happen every time? yes Other information: Versions: libxml2-2.6.31 compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv ISO8859X Unicode Regexps Automata Expr Schemas Schematron Modules Debug Zlib rpm from openSuse 10.3 XML repository. The input files: ============================ foo.rng <?xml version="1.0"?> <grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:s="http://foo.cz/"> <start> <choice> <ref name="foo1.1"/> <ref name="foo1.2"/> </choice> </start> <define name="foo1.1"> <externalRef href="foo_1_1.rng"/> </define> <define name="foo1.2"> <externalRef href="foo_1_2.rng"/> </define> </grammar> ====================== foo_1_1.rng <?xml version="1.0"?> <grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:s="http://foo.cz/"> <start combine="choice"> <ref name="foo.element"/> </start> <define name="version"> <value>1.1</value> </define> <define name="foo.element"> <element name="s:foo"> <attribute name="version"> <ref name="version"/> </attribute> <empty/> </element> </define> </grammar> ====================== foo_1_2.rng <?xml version="1.0"?> <grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:s="http://foo.cz/"> <include href="foo_1_1.rng"> <define name="version"> <value>1.2</value> </define> </include> <start> <ref name="foo.element"/> </start> </grammar> ====================== test.xml <?xml version="1.0" encoding="utf-8"?> <foo xmlns="http://foo.cz/" version="1.1"/>
This bug remains in 2.7.6 and it is in fact reproducible with a much simpler grammar than I gave in the original report: just split the grammar into two branches depending on an attribute of the root element. When using the reader interface (or xmllint--stream), libxml2 fails to validate against the second branch. $ echo '<test version="1"></test>' |xmllint --stream --relaxng choice.rng - - validates $ echo '<test version="2"></test>' |xmllint --stream --relaxng choice.rng - -:1: element test: Relax-NG validity error : Element test failed to validate attributes - fails to validate $ echo '<test version="2"></test>' |xmllint --relaxng choice.rng - <?xml version="1.0"?> <test version="2"/> - validates $ cat choice.rng <?xml version="1.0"?> <grammar xmlns="http://relaxng.org/ns/structure/1.0"> <start> <choice> <element name="test"> <attribute name="version"> <value>1</value> </attribute> </element> <element name="test"> <attribute name="version"> <value>2</value> </attribute> </element> </choice> </start> </grammar> $ xmllint --version xmllint: using libxml version 20706 compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv ISO8859X Unicode Regexps Automata Expr Schemas Schematron Modules Debug Zlib
Created attachment 175859 [details] [review] avoid using non-derterminist content models The problem appears to be xmlRelaxNGCompile() calls xmlRegexpIsDeterminist bug ignores the result and always uses the content model anyway. The attached patch only sets def->contModel if the automata is deterministic.
Whoah, good find Noam !!! Thanks a lot for the patch, commited: http://git.gnome.org/browse/libxml2/commit/?id=9313ae8517a7d91d7b6671d566c4013b02982ee3 Daniel