1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-01-26 10:03:34 +03:00

fixing bug #172215 about foreign namespaces by adding support for negated

* xmlregexp.c xmlschemas.c include/libxml/xmlautomata.h: fixing
  bug #172215 about foreign namespaces by adding support for
  negated string transitions. Error messages still need to be
  improved.
* test/schemas/any5* result/schemas/any5*: adding regression
  tests for this.
Daniel
This commit is contained in:
Daniel Veillard 2005-07-19 14:33:55 +00:00
parent 365c806eb5
commit 9efc476bb6
41 changed files with 223 additions and 68 deletions

View File

@ -1,4 +1,13 @@
Tue Jul 19 12:33:31 CEST 2005 Daniel Veillard <daniel@veillard.com>
Tue Jul 19 15:34:12 CEST 2005 Daniel Veillard <daniel@veillard.com>
* xmlregexp.c xmlschemas.c include/libxml/xmlautomata.h: fixing
bug #172215 about foreign namespaces by adding support for
negated string transitions. Error messages still need to be
improved.
* test/schemas/any5* result/schemas/any5*: adding regression
tests for this.
Tue Jul 19 12:33:31 CEST 2005 Daniel Veillard <daniel@veillard.com>
* tree.c: applied patch from Alexander Pohoyda fixing xmlGetNodePath
on namespaced attributes #310417.

View File

@ -65,6 +65,14 @@ XMLPUBFUN xmlAutomataStatePtr XMLCALL
const xmlChar *token,
const xmlChar *token2,
void *data);
XMLPUBFUN xmlAutomataStatePtr XMLCALL
xmlAutomataNewNegTrans (xmlAutomataPtr am,
xmlAutomataStatePtr from,
xmlAutomataStatePtr to,
const xmlChar *token,
const xmlChar *token2,
void *data);
XMLPUBFUN xmlAutomataStatePtr XMLCALL
xmlAutomataNewCountTrans (xmlAutomataPtr am,
xmlAutomataStatePtr from,

1
result/schemas/any5_0_0 Normal file
View File

@ -0,0 +1 @@
./test/schemas/any5_0.xml fails to validate

View File

@ -0,0 +1 @@
./test/schemas/any5_0.xml:4: element foo: Schemas validity error : Element '{urn:test:foo}foo': Missing child element(s).

1
result/schemas/any5_0_1 Normal file
View File

@ -0,0 +1 @@
./test/schemas/any5_1.xml fails to validate

View File

@ -0,0 +1 @@
./test/schemas/any5_1.xml:11: element boo: Schemas validity error : Element '{urn:test:bar}boo': This element is not expected.

1
result/schemas/any5_0_2 Normal file
View File

@ -0,0 +1 @@
./test/schemas/any5_2.xml fails to validate

View File

@ -0,0 +1 @@
./test/schemas/any5_2.xml:4: element foo: Schemas validity error : Element '{urn:test:foo}foo': Missing child element(s).

1
result/schemas/any5_0_3 Normal file
View File

@ -0,0 +1 @@
./test/schemas/any5_3.xml validates

View File

1
result/schemas/any5_0_4 Normal file
View File

@ -0,0 +1 @@
./test/schemas/any5_4.xml fails to validate

View File

@ -0,0 +1 @@
./test/schemas/any5_4.xml:11: element boo: Schemas validity error : Element '{urn:test:bar}boo': This element is not expected.

1
result/schemas/any5_0_5 Normal file
View File

@ -0,0 +1 @@
./test/schemas/any5_5.xml fails to validate

View File

@ -0,0 +1 @@
./test/schemas/any5_5.xml:11: element boo: Schemas validity error : Element '{urn:test:foo}boo': This element is not expected.

1
result/schemas/any5_0_6 Normal file
View File

@ -0,0 +1 @@
./test/schemas/any5_6.xml fails to validate

View File

@ -0,0 +1 @@
./test/schemas/any5_6.xml:11: element boo: Schemas validity error : Element '{urn:test:bar}boo': This element is not expected.

1
result/schemas/any5_1_0 Normal file
View File

@ -0,0 +1 @@
./test/schemas/any5_0.xml fails to validate

View File

@ -0,0 +1 @@
./test/schemas/any5_0.xml:4: element foo: Schemas validity error : Element '{urn:test:foo}foo': Missing child element(s).

1
result/schemas/any5_1_1 Normal file
View File

@ -0,0 +1 @@
./test/schemas/any5_1.xml fails to validate

View File

@ -0,0 +1 @@
./test/schemas/any5_1.xml:11: element boo: Schemas validity error : Element '{urn:test:bar}boo': This element is not expected. Expected is ( {urn:test:foo}boo ).

1
result/schemas/any5_1_2 Normal file
View File

@ -0,0 +1 @@
./test/schemas/any5_2.xml validates

View File

1
result/schemas/any5_1_3 Normal file
View File

@ -0,0 +1 @@
./test/schemas/any5_3.xml fails to validate

View File

@ -0,0 +1 @@
./test/schemas/any5_3.xml:4: element foo: Schemas validity error : Element '{urn:test:foo}foo': Missing child element(s).

1
result/schemas/any5_1_4 Normal file
View File

@ -0,0 +1 @@
./test/schemas/any5_4.xml fails to validate

View File

@ -0,0 +1 @@
./test/schemas/any5_4.xml:11: element boo: Schemas validity error : Element '{urn:test:bar}boo': This element is not expected. Expected is ( {urn:test:foo}boo ).

1
result/schemas/any5_1_5 Normal file
View File

@ -0,0 +1 @@
./test/schemas/any5_5.xml validates

View File

1
result/schemas/any5_1_6 Normal file
View File

@ -0,0 +1 @@
./test/schemas/any5_6.xml fails to validate

View File

@ -0,0 +1 @@
./test/schemas/any5_6.xml:11: element boo: Schemas validity error : Element '{urn:test:bar}boo': This element is not expected. Expected is ( {urn:test:foo}boo ).

7
test/schemas/any5_0.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<foo xmlns="urn:test:foo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:test:foo any5_0.xsd">
<boo/>
<boo/>
</foo>

13
test/schemas/any5_0.xsd Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:test:foo"
elementFormDefault="qualified">
<xsd:element name="foo">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="boo"/>
<xsd:any namespace="##other" maxOccurs="5" processContents="lax"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

12
test/schemas/any5_1.xml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<foo xmlns="urn:test:foo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:test:foo any5_0.xsd">
<boo/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
</foo>

14
test/schemas/any5_1.xsd Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:test:foo"
elementFormDefault="qualified">
<xsd:element name="foo">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="boo"/>
<xsd:any namespace="##other" maxOccurs="5" processContents="lax"/>
<xsd:element name="boo"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

8
test/schemas/any5_2.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<foo xmlns="urn:test:foo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:test:foo any5_0.xsd">
<boo/>
<boo xmlns="urn:test:bar"/>
<boo/>
</foo>

11
test/schemas/any5_3.xml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<foo xmlns="urn:test:foo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:test:foo any5_0.xsd">
<boo/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
</foo>

12
test/schemas/any5_4.xml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<foo xmlns="urn:test:foo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:test:foo any5_0.xsd">
<boo/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
</foo>

12
test/schemas/any5_5.xml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<foo xmlns="urn:test:foo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:test:foo any5_0.xsd">
<boo/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo/>
</foo>

13
test/schemas/any5_6.xml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<foo xmlns="urn:test:foo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:test:foo any5_0.xsd">
<boo/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo xmlns="urn:test:bar"/>
<boo/>
</foo>

View File

@ -329,6 +329,7 @@ struct _xmlRegExecCtxt {
static void xmlFAParseRegExp(xmlRegParserCtxtPtr ctxt, int top);
static void xmlRegFreeState(xmlRegStatePtr state);
static void xmlRegFreeAtom(xmlRegAtomPtr atom);
static int xmlRegStrEqualWildcard(const xmlChar *expStr, const xmlChar *valStr);
/************************************************************************
* *
@ -971,6 +972,8 @@ xmlRegPrintAtom(FILE *output, xmlRegAtomPtr atom) {
fprintf(output, "NULL\n");
return;
}
if (atom->neg)
fprintf(output, "not ");
xmlRegPrintAtomType(output, atom->type);
xmlRegPrintQuantType(output, atom->quant);
if (atom->quant == XML_REGEXP_QUANT_RANGE)
@ -1741,6 +1744,8 @@ xmlFAEliminateEpsilonTransitions(xmlRegParserCtxtPtr ctxt) {
*/
static int
xmlFACompareAtoms(xmlRegAtomPtr atom1, xmlRegAtomPtr atom2) {
int ret;
if (atom1 == atom2)
return(1);
if ((atom1 == NULL) || (atom2 == NULL))
@ -1750,19 +1755,23 @@ xmlFACompareAtoms(xmlRegAtomPtr atom1, xmlRegAtomPtr atom2) {
return(0);
switch (atom1->type) {
case XML_REGEXP_STRING:
return(xmlStrEqual((xmlChar *)atom1->valuep,
(xmlChar *)atom2->valuep));
ret = xmlRegStrEqualWildcard((xmlChar *)atom1->valuep,
(xmlChar *)atom2->valuep);
break;
case XML_REGEXP_EPSILON:
return(1);
case XML_REGEXP_CHARVAL:
return(atom1->codepoint == atom2->codepoint);
ret = atom1->codepoint == atom2->codepoint;
break;
case XML_REGEXP_RANGES:
TODO;
return(0);
default:
break;
return(1);
}
return(1);
if (atom1->neg != atom2->neg)
ret = !ret;
return(ret);
}
/**
@ -2907,6 +2916,8 @@ xmlRegExecPushString(xmlRegExecCtxtPtr exec, const xmlChar *value,
break;
} else if (value != NULL) {
ret = xmlRegStrEqualWildcard(atom->valuep, value);
if (atom->neg)
ret = !ret;
if ((ret == 1) && (trans->counter >= 0)) {
xmlRegCounterPtr counter;
int count;
@ -4735,6 +4746,65 @@ xmlAutomataNewTransition2(xmlAutomataPtr am, xmlAutomataStatePtr from,
return(to);
}
/**
* xmlAutomataNewNegTrans:
* @am: an automata
* @from: the starting point of the transition
* @to: the target point of the transition or NULL
* @token: the first input string associated to that transition
* @token2: the second input string associated to that transition
* @data: data passed to the callback function if the transition is activated
*
* If @to is NULL, this creates first a new target state in the automata
* and then adds a transition from the @from state to the target state
* activated by any value except (@token,@token2)
*
* Returns the target state or NULL in case of error
*/
xmlAutomataStatePtr
xmlAutomataNewNegTrans(xmlAutomataPtr am, xmlAutomataStatePtr from,
xmlAutomataStatePtr to, const xmlChar *token,
const xmlChar *token2, void *data) {
xmlRegAtomPtr atom;
if ((am == NULL) || (from == NULL) || (token == NULL))
return(NULL);
atom = xmlRegNewAtom(am, XML_REGEXP_STRING);
if (atom == NULL)
return(NULL);
atom->data = data;
atom->neg = 1;
if ((token2 == NULL) || (*token2 == 0)) {
atom->valuep = xmlStrdup(token);
} else {
int lenn, lenp;
xmlChar *str;
lenn = strlen((char *) token2);
lenp = strlen((char *) token);
str = (xmlChar *) xmlMallocAtomic(lenn + lenp + 2);
if (str == NULL) {
xmlRegFreeAtom(atom);
return(NULL);
}
memcpy(&str[0], token, lenp);
str[lenp] = '|';
memcpy(&str[lenp + 1], token2, lenn);
str[lenn + lenp + 1] = 0;
atom->valuep = str;
}
if (xmlFAGenerateTransitions(am, from, to, atom) < 0) {
xmlRegFreeAtom(atom);
return(NULL);
}
if (to == NULL)
return(am->state);
return(to);
}
/**
* xmlAutomataNewCountTrans2:
* @am: an automata

View File

@ -11132,14 +11132,9 @@ xmlSchemaBuildAContentModel(xmlSchemaParserCtxtPtr ctxt,
} while (ns != NULL);
} else if (wild->negNsSet != NULL) {
xmlAutomataStatePtr deadEnd;
deadEnd = xmlAutomataNewState(ctxt->am);
ctxt->state = xmlAutomataNewTransition2(ctxt->am,
start, deadEnd, BAD_CAST "*", wild->negNsSet->value, wild);
ctxt->state = xmlAutomataNewTransition2(ctxt->am,
start, NULL, BAD_CAST "*", BAD_CAST "*", wild);
xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop);
ctxt->state = xmlAutomataNewNegTrans(ctxt->am,
start, hop, BAD_CAST "*", wild->negNsSet->value,
wild);
}
xmlAutomataNewCountedTrans(ctxt->am, hop, start, counter);
xmlAutomataNewCounterTrans(ctxt->am, hop, end, counter);
@ -11384,60 +11379,6 @@ xmlSchemaBuildAContentModel(xmlSchemaParserCtxtPtr ctxt,
ctxt->state =
xmlAutomataNewAllTrans(ctxt->am, ctxt->state, NULL, lax);
break;
#if 0
xmlAutomataStatePtr start, end, base;
xmlSchemaParticlePtr sub;
xmlSchemaElementPtr elemDecl;
int nbtrans = 0;
int lax = particle->minOccurs == 0;
int counter = -1;
sub = (xmlSchemaParticlePtr) particle->children->children;
if (sub == NULL)
break;
start = ctxt->state;
end = xmlAutomataNewState(ctxt->am);
base = xmlAutomataNewState(ctxt->am);
xmlAutomataNewEpsilon(ctxt->am, start, base);
if (!lax) {
while (sub != NULL) {
sub = (xmlSchemaParticlePtr) sub->next;
nbtrans++;
}
sub = (xmlSchemaParticlePtr) particle->children->children;
nbtrans--;
counter = xmlAutomataNewCounter(ctxt->am, nbtrans, nbtrans);
}
while (sub != NULL) {
ctxt->state = base;
elemDecl = (xmlSchemaElementPtr) sub->children;
if (elemDecl == NULL) {
xmlSchemaPErr(ctxt, NULL,
XML_SCHEMAP_INTERNAL,
"Internal error: xmlSchemaBuildAContentModel, "
"<element> particle a NULL term.\n", NULL, NULL);
return;
};
xmlSchemaBuildContentModelForElement(ctxt,
(xmlSchemaParticlePtr) sub, 1);
if (lax) {
xmlAutomataNewEpsilon(ctxt->am, ctxt->state, base);
xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end);
} else {
xmlAutomataNewCountedTrans(ctxt->am, ctxt->state,
base, counter);
xmlAutomataNewCounterTrans(ctxt->am, ctxt->state,
end, counter);
}
sub = (xmlSchemaParticlePtr) sub->next;
}
ctxt->state = end;
break;
#endif
}
default:
xmlGenericError(xmlGenericErrorContext,