mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-30 22:43:14 +03:00
patched a bug in parsing production 1 and 2 of xmlschemas regexp that
* xmlregexp.c: patched a bug in parsing production 1 and 2 of xmlschemas regexp that William pointed out while working on #134120 * test/regexp/branch result/regexp/branch: added a specific regression test Daniel
This commit is contained in:
@ -1,3 +1,11 @@
|
|||||||
|
Wed Mar 31 17:47:28 CEST 2004 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* xmlregexp.c: patched a bug in parsing production 1 and 2 of
|
||||||
|
xmlschemas regexp that William pointed out while working on
|
||||||
|
#134120
|
||||||
|
* test/regexp/branch result/regexp/branch: added a specific
|
||||||
|
regression test
|
||||||
|
|
||||||
Wed Mar 31 09:50:32 HKT 2004 William Brack <wbrack@mmm.com.hk>
|
Wed Mar 31 09:50:32 HKT 2004 William Brack <wbrack@mmm.com.hk>
|
||||||
|
|
||||||
* Makefile.am: added PYTHONPATH to python tests for Schemas
|
* Makefile.am: added PYTHONPATH to python tests for Schemas
|
||||||
|
14
result/regexp/branch
Normal file
14
result/regexp/branch
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
Regexp: a|b(d|e(g|h|i)|f)|c
|
||||||
|
a: Ok
|
||||||
|
c: Ok
|
||||||
|
bd: Ok
|
||||||
|
bf: Ok
|
||||||
|
beg: Ok
|
||||||
|
beh: Ok
|
||||||
|
bei: Ok
|
||||||
|
b: Fail
|
||||||
|
be: Fail
|
||||||
|
bi: Fail
|
||||||
|
f: Fail
|
||||||
|
ab: Fail
|
||||||
|
ac: Fail
|
14
test/regexp/branch
Normal file
14
test/regexp/branch
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
=>a|b(d|e(g|h|i)|f)|c
|
||||||
|
a
|
||||||
|
c
|
||||||
|
bd
|
||||||
|
bf
|
||||||
|
beg
|
||||||
|
beh
|
||||||
|
bei
|
||||||
|
b
|
||||||
|
be
|
||||||
|
bi
|
||||||
|
f
|
||||||
|
ab
|
||||||
|
ac
|
71
xmlregexp.c
71
xmlregexp.c
@ -1214,14 +1214,15 @@ xmlRegStateAddTrans(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr state,
|
|||||||
#ifdef DEBUG_REGEXP_GRAPH
|
#ifdef DEBUG_REGEXP_GRAPH
|
||||||
printf("Add trans from %d to %d ", state->no, target->no);
|
printf("Add trans from %d to %d ", state->no, target->no);
|
||||||
if (count == REGEXP_ALL_COUNTER)
|
if (count == REGEXP_ALL_COUNTER)
|
||||||
printf("all transition");
|
printf("all transition\n");
|
||||||
else if (count >= 0)
|
else if (count >= 0)
|
||||||
printf("count based %d", count);
|
printf("count based %d\n", count);
|
||||||
else if (counter >= 0)
|
else if (counter >= 0)
|
||||||
printf("counted %d", counter);
|
printf("counted %d\n", counter);
|
||||||
else if (atom == NULL)
|
else if (atom == NULL)
|
||||||
printf("epsilon transition");
|
printf("epsilon transition\n");
|
||||||
printf("\n");
|
else if (atom != NULL)
|
||||||
|
xmlRegPrintAtom(stdout, atom);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
state->trans[state->nbTrans].atom = atom;
|
state->trans[state->nbTrans].atom = atom;
|
||||||
@ -3862,50 +3863,33 @@ xmlFAParsePiece(xmlRegParserCtxtPtr ctxt) {
|
|||||||
/**
|
/**
|
||||||
* xmlFAParseBranch:
|
* xmlFAParseBranch:
|
||||||
* @ctxt: a regexp parser context
|
* @ctxt: a regexp parser context
|
||||||
* @first: is taht the first
|
|
||||||
*
|
*
|
||||||
* [2] branch ::= piece*
|
* [2] branch ::= piece*
|
||||||
8
|
8
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
xmlFAParseBranch(xmlRegParserCtxtPtr ctxt, int first) {
|
xmlFAParseBranch(xmlRegParserCtxtPtr ctxt) {
|
||||||
xmlRegStatePtr previous;
|
xmlRegStatePtr previous;
|
||||||
xmlRegAtomPtr prevatom = NULL;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
previous = ctxt->state;
|
previous = ctxt->state;
|
||||||
ret = xmlFAParsePiece(ctxt);
|
ret = xmlFAParsePiece(ctxt);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
if (first) {
|
if (xmlFAGenerateTransitions(ctxt, previous, NULL, ctxt->atom) < 0)
|
||||||
if (xmlFAGenerateTransitions(ctxt, previous, NULL, ctxt->atom) < 0)
|
return(-1);
|
||||||
return(-1);
|
previous = ctxt->state;
|
||||||
previous = ctxt->state;
|
|
||||||
} else {
|
|
||||||
prevatom = ctxt->atom;
|
|
||||||
}
|
|
||||||
ctxt->atom = NULL;
|
ctxt->atom = NULL;
|
||||||
}
|
}
|
||||||
while ((ret != 0) && (ctxt->error == 0)) {
|
while ((ret != 0) && (ctxt->error == 0)) {
|
||||||
ret = xmlFAParsePiece(ctxt);
|
ret = xmlFAParsePiece(ctxt);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
if (first) {
|
if (xmlFAGenerateTransitions(ctxt, previous, NULL,
|
||||||
if (xmlFAGenerateTransitions(ctxt, previous, NULL,
|
ctxt->atom) < 0)
|
||||||
ctxt->atom) < 0)
|
|
||||||
return(-1);
|
return(-1);
|
||||||
} else {
|
|
||||||
if (xmlFAGenerateTransitions(ctxt, previous, NULL,
|
|
||||||
prevatom) < 0)
|
|
||||||
return(-1);
|
|
||||||
prevatom = ctxt->atom;
|
|
||||||
}
|
|
||||||
previous = ctxt->state;
|
previous = ctxt->state;
|
||||||
ctxt->atom = NULL;
|
ctxt->atom = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!first) {
|
|
||||||
if (xmlFAGenerateTransitions(ctxt, previous, ctxt->end, prevatom) < 0)
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3918,12 +3902,21 @@ xmlFAParseBranch(xmlRegParserCtxtPtr ctxt, int first) {
|
|||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
xmlFAParseRegExp(xmlRegParserCtxtPtr ctxt, int top) {
|
xmlFAParseRegExp(xmlRegParserCtxtPtr ctxt, int top) {
|
||||||
xmlRegStatePtr start, end, oldend;
|
xmlRegStatePtr start, end, oldend, oldstart;
|
||||||
|
|
||||||
oldend = ctxt->end;
|
oldend = ctxt->end;
|
||||||
|
|
||||||
|
oldstart = ctxt->state;
|
||||||
|
/* if not top start should have been generated by an epsilon trans */
|
||||||
start = ctxt->state;
|
start = ctxt->state;
|
||||||
xmlFAParseBranch(ctxt, (ctxt->end == NULL));
|
ctxt->end = NULL;
|
||||||
|
xmlFAParseBranch(ctxt);
|
||||||
|
if (top) {
|
||||||
|
#ifdef DEBUG_REGEXP_GRAPH
|
||||||
|
printf("State %d is final\n", ctxt->state->no);
|
||||||
|
#endif
|
||||||
|
ctxt->state->type = XML_REGEXP_FINAL_STATE;
|
||||||
|
}
|
||||||
if (CUR != '|') {
|
if (CUR != '|') {
|
||||||
ctxt->end = ctxt->state;
|
ctxt->end = ctxt->state;
|
||||||
return;
|
return;
|
||||||
@ -3932,11 +3925,21 @@ xmlFAParseRegExp(xmlRegParserCtxtPtr ctxt, int top) {
|
|||||||
while ((CUR == '|') && (ctxt->error == 0)) {
|
while ((CUR == '|') && (ctxt->error == 0)) {
|
||||||
NEXT;
|
NEXT;
|
||||||
ctxt->state = start;
|
ctxt->state = start;
|
||||||
ctxt->end = end;
|
ctxt->end = NULL;
|
||||||
xmlFAParseBranch(ctxt, 0);
|
xmlFAParseBranch(ctxt);
|
||||||
|
if (top) {
|
||||||
|
ctxt->state->type = XML_REGEXP_FINAL_STATE;
|
||||||
|
#ifdef DEBUG_REGEXP_GRAPH
|
||||||
|
printf("State %d is final\n", ctxt->state->no);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
xmlFAGenerateEpsilonTransition(ctxt, ctxt->state, end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!top) {
|
||||||
|
ctxt->state = end;
|
||||||
|
ctxt->end = end;
|
||||||
}
|
}
|
||||||
if (!top)
|
|
||||||
ctxt->end = oldend;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
|
Reference in New Issue
Block a user