fixed the last core RelaxNG bug known #107083, shemas datatype ID/IDREF

* relaxng.c: fixed the last core RelaxNG bug known #107083,
  shemas datatype ID/IDREF support still missing though.
* xmlreader.c: fix a crashing bug with prefix raised by
  Merijn Broeren
* test/relaxng/testsuite.xml: augmented the testsuite with
  complex inheritance tests
Daniel
This commit is contained in:
Daniel Veillard 2003-03-17 15:37:12 +00:00
parent b4d30b6360
commit 952379b780
5 changed files with 653 additions and 7 deletions

View File

@ -1,3 +1,12 @@
Mon Mar 17 16:34:07 CET 2003 Daniel Veillard <daniel@veillard.com>
* relaxng.c: fixed the last core RelaxNG bug known #107083,
shemas datatype ID/IDREF support still missing though.
* xmlreader.c: fix a crashing bug with prefix raised by
Merijn Broeren
* test/relaxng/testsuite.xml: augmented the testsuite with
complex inheritance tests
Sun Mar 16 18:45:50 CET 2003 Daniel Veillard <daniel@veillard.com>
* relaxng.c: switched back to the previous Relax-NG code base,

View File

@ -68,7 +68,8 @@ typedef enum {
XML_RELAXNG_ERR_LIST,
XML_RELAXNG_ERR_NOGRAMMAR,
XML_RELAXNG_ERR_EXTRADATA,
XML_RELAXNG_ERR_LACKDATA
XML_RELAXNG_ERR_LACKDATA,
XML_RELAXNG_ERR_INTERNAL
} xmlRelaxNGValidErr;
/*

View File

@ -47,7 +47,7 @@ static const xmlChar *xmlRelaxNGNs = (const xmlChar *)
(xmlStrEqual(node->ns->href, xmlRelaxNGNs)))
/* #define DEBUG 1 */
/* #define DEBUG 1 */
/* #define DEBUG_GRAMMAR 1 */
/* #define DEBUG_CONTENT 1 */
/* #define DEBUG_TYPE 1 */
@ -1114,8 +1114,12 @@ xmlRelaxNGRemoveRedefine(xmlRelaxNGParserCtxtPtr ctxt,
xmlChar *name2;
#ifdef DEBUG_INCLUDE
xmlGenericError(xmlGenericErrorContext,
"Elimination of <include> %s from %s\n", name, URL);
if (name == NULL)
xmlGenericError(xmlGenericErrorContext,
"Elimination of <include> start from %s\n", URL);
else
xmlGenericError(xmlGenericErrorContext,
"Elimination of <include> define %s from %s\n", name, URL);
#endif
tmp = target;
while (tmp != NULL) {
@ -1665,6 +1669,9 @@ xmlRelaxNGGetErrorString(xmlRelaxNGValidErr err, const xmlChar *arg1,
return(xmlCharStrdup("Internal error: no state"));
case XML_RELAXNG_ERR_NODEFINE:
return(xmlCharStrdup("Internal error: no define"));
case XML_RELAXNG_ERR_INTERNAL:
snprintf(msg, 1000, "Internal error: %s", arg1);
break;
case XML_RELAXNG_ERR_LISTEXTRA:
snprintf(msg, 1000, "Extra data in list: %s", arg1);
break;
@ -2297,6 +2304,72 @@ xmlRelaxNGCleanupTypes(void) {
xmlRelaxNGTypeInitialized = 0;
}
/************************************************************************
* *
* Compiling element content into regexp *
* *
* Sometime the element content can be compiled into a pure regexp, *
* This allows a faster execution and streamability at that level *
* *
************************************************************************/
/**
* xmlRelaxNGIsCompileable:
* @define: the definition to check
*
* Check if a definition is nullable.
*
* Returns 1 if yes, 0 if no and -1 in case of error
*/
static int
xmlRelaxNGIsCompileable(xmlRelaxNGDefinePtr def) {
if (def == NULL) {
return(-1);
}
switch(def->type) {
case XML_RELAXNG_REF:
case XML_RELAXNG_EXTERNALREF:
case XML_RELAXNG_PARENTREF:
case XML_RELAXNG_NOOP:
case XML_RELAXNG_START:
return(xmlRelaxNGIsCompileable(def->content));
case XML_RELAXNG_TEXT:
case XML_RELAXNG_DATATYPE:
case XML_RELAXNG_LIST:
case XML_RELAXNG_PARAM:
case XML_RELAXNG_VALUE:
case XML_RELAXNG_EMPTY:
case XML_RELAXNG_ELEMENT:
return(1);
case XML_RELAXNG_OPTIONAL:
case XML_RELAXNG_ZEROORMORE:
case XML_RELAXNG_ONEORMORE:
case XML_RELAXNG_CHOICE:
case XML_RELAXNG_GROUP:
case XML_RELAXNG_DEF: {
xmlRelaxNGDefinePtr list;
int ret;
list = def->content;
while (list != NULL) {
ret = xmlRelaxNGIsCompileable(list);
if (ret != 1)
return(ret);
list = list->next;
}
return(1);
}
case XML_RELAXNG_EXCEPT:
case XML_RELAXNG_ATTRIBUTE:
case XML_RELAXNG_INTERLEAVE:
return(0);
case XML_RELAXNG_NOT_ALLOWED:
return(-1);
}
return(-1);
}
/************************************************************************
* *
* Parsing functions *
@ -2927,6 +3000,7 @@ xmlRelaxNGGetElements(xmlRelaxNGParserCtxtPtr ctxt,
(cur->type == XML_RELAXNG_ONEORMORE) ||
(cur->type == XML_RELAXNG_ZEROORMORE) ||
(cur->type == XML_RELAXNG_OPTIONAL) ||
(cur->type == XML_RELAXNG_PARENTREF) ||
(cur->type == XML_RELAXNG_REF) ||
(cur->type == XML_RELAXNG_DEF)) {
/*
@ -4598,8 +4672,8 @@ xmlRelaxNGCheckCombine(xmlRelaxNGDefinePtr define,
last->next = tmp2;
}
last = tmp2;
tmp->content = NULL;
}
tmp->content = cur;
tmp = tmp->nextHash;
}
define->content = cur;
@ -5373,6 +5447,7 @@ xmlRelaxNGParseGrammar(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr nodes) {
xmlHashScan(ret->refs, (xmlHashScanner) xmlRelaxNGCheckReference,
ctxt);
}
ctxt->grammar = old;
return(ret);
}
@ -7386,6 +7461,10 @@ xmlRelaxNGValidateDefinitionList(xmlRelaxNGValidCtxtPtr ctxt,
int ret = 0, res;
if (defines == NULL) {
VALID_ERR2(XML_RELAXNG_ERR_INTERNAL, BAD_CAST "NULL definition list");
return(-1);
}
while (defines != NULL) {
if ((ctxt->state != NULL) || (ctxt->states != NULL)) {
res = xmlRelaxNGValidateDefinition(ctxt, defines);
@ -7934,10 +8013,12 @@ xmlRelaxNGValidateState(xmlRelaxNGValidCtxtPtr ctxt,
break;
case XML_RELAXNG_NOOP:
case XML_RELAXNG_REF:
case XML_RELAXNG_PARENTREF:
case XML_RELAXNG_EXTERNALREF:
ret = xmlRelaxNGValidateDefinition(ctxt, define->content);
break;
case XML_RELAXNG_PARENTREF:
ret = xmlRelaxNGValidateDefinition(ctxt, define->content);
break;
case XML_RELAXNG_DATATYPE: {
xmlNodePtr child;
xmlChar *content = NULL;

View File

@ -776,4 +776,559 @@
</invalid>
</testCase>
</testSuite>
<testSuite>
<documentation>Test of grammars merging</documentation>
<testCase>
<resource name="dbk.rng">
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<ref name="p"/>
</start>
<define name="p.ext">
<notAllowed/>
</define>
<define name="p">
<element name="p">
<choice>
<ref name="p.ext"/>
<empty/>
<element name="a">
<text/>
</element>
</choice>
</element>
</define>
</grammar>
</resource>
<correct>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<grammar>
<include href="dbk.rng"/>
<define name="p.ext" combine="choice">
<element name="b">
<text/>
</element>
</define>
</grammar>
</start>
</grammar>
</correct>
<valid>
<p/>
</valid>
<valid>
<p>
<a/>
</p>
</valid>
<valid>
<p>
<b/>
</p>
</valid>
<invalid>
<b/>
</invalid>
<invalid>
<p>
<b/>
<b/>
</p>
</invalid>
</testCase>
<testCase>
<resource name="dbk.rng">
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<ref name="p"/>
</start>
<define name="p.ext">
<notAllowed/>
</define>
<define name="p">
<element name="p">
<choice>
<ref name="p.ext"/>
<empty/>
<element name="a">
<text/>
</element>
</choice>
</element>
</define>
<define name="c">
<element name="c">
<empty/>
</element>
</define>
</grammar>
</resource>
<correct>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<grammar>
<include href="dbk.rng"/>
<define name="p.ext" combine="choice">
<choice>
<ref name="c"/>
<parentRef name="d"/>
<element name="b">
<text/>
</element>
</choice>
</define>
</grammar>
</start>
<define name="d">
<element name="d">
<empty/>
</element>
</define>
</grammar>
</correct>
<valid>
<p/>
</valid>
<valid>
<p>
<a/>
</p>
</valid>
<valid>
<p>
<b/>
</p>
</valid>
<valid>
<p>
<c/>
</p>
</valid>
<valid>
<p>
<d/>
</p>
</valid>
<invalid>
<b/>
</invalid>
<invalid>
<c/>
</invalid>
<invalid>
<d/>
</invalid>
<invalid>
<p>
<b/>
<c/>
</p>
</invalid>
<invalid>
<p>
<d/>
<c/>
</p>
</invalid>
</testCase>
<testCase>
<resource name="dbk.rng">
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<ref name="p"/>
</start>
<define name="p.ext">
<notAllowed/>
</define>
<define name="p">
<element name="p">
<choice>
<ref name="p.ext"/>
<empty/>
<element name="a">
<text/>
</element>
</choice>
</element>
</define>
<define name="c">
<element name="c">
<empty/>
</element>
</define>
</grammar>
</resource>
<resource name="proof.rng">
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<ref name="e"/>
</start>
<define name="d">
<element name="d">
<empty/>
</element>
</define>
<define name="e">
<element name="e">
<empty/>
</element>
</define>
<define name="f">
<element name="f">
<empty/>
</element>
</define>
</grammar>
</resource>
<correct>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<grammar>
<include href="dbk.rng"/>
<define name="p.ext" combine="choice">
<choice>
<ref name="c"/>
<grammar>
<include href="proof.rng"/>
<start combine="choice">
<ref name="d"/>
</start>
</grammar>
<element name="b">
<text/>
</element>
</choice>
</define>
</grammar>
</start>
<define name="g">
<element name="g">
<empty/>
</element>
</define>
</grammar>
</correct>
<valid>
<p/>
</valid>
<valid>
<p>
<a/>
</p>
</valid>
<valid>
<p>
<b/>
</p>
</valid>
<valid>
<p>
<c/>
</p>
</valid>
<valid>
<p>
<d/>
</p>
</valid>
<valid>
<p>
<e/>
</p>
</valid>
<invalid>
<p>
<f/>
</p>
</invalid>
<invalid>
<p>
<g/>
</p>
</invalid>
<invalid>
<b/>
</invalid>
<invalid>
<c/>
</invalid>
<invalid>
<d/>
</invalid>
<invalid>
<e/>
</invalid>
<invalid>
<f/>
</invalid>
<invalid>
<g/>
</invalid>
<invalid>
<p>
<d/>
<c/>
</p>
</invalid>
<invalid>
<p>
<d/>
<e/>
</p>
</invalid>
</testCase>
<testCase>
<resource name="dbk.rng">
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<ref name="p"/>
</start>
<define name="p.ext">
<notAllowed/>
</define>
<define name="p">
<element name="p">
<choice>
<ref name="p.ext"/>
<empty/>
<element name="a">
<text/>
</element>
</choice>
</element>
</define>
<define name="c">
<element name="c">
<empty/>
</element>
</define>
</grammar>
</resource>
<resource name="proof.rng">
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
ns="http://example.org/ns/proofsystem">
<start>
<ref name="e"/>
</start>
<define name="d">
<element name="d">
<empty/>
</element>
</define>
<define name="e">
<element name="e">
<empty/>
</element>
</define>
<define name="f">
<element name="f">
<empty/>
</element>
</define>
</grammar>
</resource>
<correct>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<grammar>
<include href="dbk.rng"/>
<define name="p.ext" combine="choice">
<choice>
<ref name="c"/>
<grammar>
<include href="proof.rng"/>
<start combine="choice">
<ref name="d"/>
</start>
</grammar>
<element name="b">
<text/>
</element>
</choice>
</define>
</grammar>
</start>
<define name="g">
<element name="g">
<empty/>
</element>
</define>
</grammar>
</correct>
<valid>
<p/>
</valid>
<valid>
<p>
<a/>
</p>
</valid>
<valid>
<p>
<b/>
</p>
</valid>
<valid>
<p>
<c/>
</p>
</valid>
<valid>
<p xmlns:p="http://example.org/ns/proofsystem">
<p:d/>
</p>
</valid>
<invalid>
<p>
<d/>
</p>
</invalid>
<valid>
<p xmlns:p="http://example.org/ns/proofsystem">
<p:e/>
</p>
</valid>
<invalid>
<p>
<e/>
</p>
</invalid>
<invalid>
<p xmlns:p="http://example.org/ns/proofsystem">
<p:f/>
</p>
</invalid>
<invalid>
<p>
<f/>
</p>
</invalid>
<invalid>
<p>
<g/>
</p>
</invalid>
<invalid>
<b/>
</invalid>
<invalid>
<c/>
</invalid>
<invalid>
<d/>
</invalid>
<invalid>
<e/>
</invalid>
<invalid>
<f/>
</invalid>
<invalid>
<g/>
</invalid>
<invalid>
<p xmlns:p="http://example.org/ns/proofsystem">
<p:d/>
<c/>
</p>
</invalid>
<invalid>
<p xmlns:p="http://example.org/ns/proofsystem">
<p:d/>
<p:e/>
</p>
</invalid>
</testCase>
<testCase>
<resource name="ext.rng">
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<ref name="p"/>
</start>
<define name="p">
<element name="p">
<empty/>
</element>
</define>
</grammar>
</resource>
<correct>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<element name="top">
<choice>
<ref name="include1"/>
<ref name="include2"/>
</choice>
</element>
</start>
<define name="include1">
<grammar>
<include href="ext.rng">
<start>
<element name="a">
<choice>
<empty/>
<ref name="p"/>
</choice>
</element>
</start>
</include>
</grammar>
</define>
<define name="include2">
<grammar>
<include href="ext.rng">
<start>
<element name="b">
<choice>
<empty/>
<ref name="p"/>
</choice>
</element>
</start>
</include>
</grammar>
</define>
</grammar>
</correct>
<invalid>
<top/>
</invalid>
<invalid>
<a/>
</invalid>
<invalid>
<b/>
</invalid>
<invalid>
<p/>
</invalid>
<valid>
<top>
<a/>
</top>
</valid>
<valid>
<top>
<b/>
</top>
</valid>
<valid>
<top>
<a>
<p/>
</a>
</top>
</valid>
<valid>
<top>
<b>
<p/>
</b>
</top>
</valid>
</testCase>
</testSuite>
</testSuite>

View File

@ -1865,7 +1865,7 @@ xmlTextReaderPrefix(xmlTextReaderPtr reader) {
if ((node->type != XML_ELEMENT_NODE) &&
(node->type != XML_ATTRIBUTE_NODE))
return(NULL);
if ((node->ns != NULL) || (node->ns->prefix != NULL))
if ((node->ns != NULL) && (node->ns->prefix != NULL))
return(xmlStrdup(node->ns->prefix));
return(NULL);
}