diff --git a/ChangeLog b/ChangeLog index a5f487ea..a1bb3b91 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Sun Aug 3 21:02:30 EDT 2003 Daniel Veillard + + * tree.c include/libxml/tree.h: added a new API to split a + QName without generating any memory allocation + * valid.c: fixed another problem with namespaces on element + in mixed content case + * python/tests/reader2.py: updated the testcase with + Bjorn Reese fix to reader for unsignificant white space + * parser.c HTMLparser.c: cleanup. + Sun Aug 3 20:55:40 EDT 2003 Daniel Veillard * catalog.c: trying to fix #118754 of possible recursion in the diff --git a/HTMLparser.c b/HTMLparser.c index 85be52db..d45eac26 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -4331,7 +4331,7 @@ htmlCreateDocParserCtxt(xmlChar *cur, const char *encoding ATTRIBUTE_UNUSED) { */ static int htmlParseLookupSequence(htmlParserCtxtPtr ctxt, xmlChar first, - xmlChar next, xmlChar third, int comment) { + xmlChar next, xmlChar third, int comment) { int base, len; htmlParserInputPtr in; const xmlChar *buf; diff --git a/include/libxml/tree.h b/include/libxml/tree.h index c8467e8e..4ca3c9ae 100644 --- a/include/libxml/tree.h +++ b/include/libxml/tree.h @@ -556,6 +556,9 @@ xmlChar * xmlBuildQName (const xmlChar *ncname, int len); xmlChar * xmlSplitQName2 (const xmlChar *name, xmlChar **prefix); +const xmlChar * xmlSplitQName3 (const xmlChar *name, + int *len); + /* * Handling Buffers. */ diff --git a/parser.c b/parser.c index 1291533c..6e448965 100644 --- a/parser.c +++ b/parser.c @@ -1789,7 +1789,7 @@ xmlSplitQName(xmlParserCtxtPtr ctxt, const xmlChar *name, xmlChar **prefix) { c = *cur; *prefix = ret; if (c == 0) { - return(xmlStrndup("", 0)); + return(xmlStrndup(BAD_CAST "", 0)); } len = 0; diff --git a/python/tests/reader2.py b/python/tests/reader2.py index afc3586a..e3252272 100755 --- a/python/tests/reader2.py +++ b/python/tests/reader2.py @@ -63,17 +63,17 @@ s = """ """ expect="""10,test 1,test -3,#text +14,#text 1,x 1,c 3,#text 15,c 15,x -3,#text +14,#text 1,b 3,#text 15,b -3,#text +14,#text 15,test """ res="" @@ -113,11 +113,11 @@ s = """hello""" expect="""10 test 1 test -3 #text +14 #text 1 x 3 #text 15 x -3 #text +14 #text 15 test """ res="" @@ -165,19 +165,19 @@ s = """""" expect="""10 test 0 1 test 0 -3 #text 1 +14 #text 1 1 x 1 1 y 2 3 #text 3 15 y 2 15 x 1 -3 #text 1 +14 #text 1 1 x 1 1 y 2 3 #text 3 15 y 2 15 x 1 -3 #text 1 +14 #text 1 15 test 0 """ res="" @@ -218,11 +218,11 @@ s = """""" expect="""10 test 0 1 test 0 -3 #text 1 +14 #text 1 5 x 1 -3 #text 1 +14 #text 1 5 x 1 -3 #text 1 +14 #text 1 15 test 0 """ res="" diff --git a/tree.c b/tree.c index 114989e0..ca1a7bb8 100644 --- a/tree.c +++ b/tree.c @@ -236,6 +236,43 @@ xmlSplitQName2(const xmlChar *name, xmlChar **prefix) { return(ret); } +/** + * xmlSplitQName3: + * @name: the full QName + * @len: an int * + * + * parse an XML qualified name string,i + * + * returns NULL if it is not a Qualified Name, otherwise, update len + * with the lenght in byte of the prefix and return a pointer + */ + +const xmlChar * +xmlSplitQName3(const xmlChar *name, int *len) { + int l = 0; + + if (name == NULL) return(NULL); + if (len == NULL) return(NULL); + + /* nasty but valid */ + if (name[0] == ':') + return(NULL); + + /* + * we are not trying to validate but just to cut, and yes it will + * work even if this is as set of UTF-8 encoded chars + */ + while ((name[l] != 0) && (name[l] != ':')) + l++; + + if (name[l] == 0) + return(NULL); + + *len = l; + + return(&name[l+1]); +} + /************************************************************************ * * * Check Name, NCName and QName strings * diff --git a/valid.c b/valid.c index 9dee4bbc..9a261f1e 100644 --- a/valid.c +++ b/valid.c @@ -5059,24 +5059,55 @@ done: static int xmlValidateCheckMixed(xmlValidCtxtPtr ctxt ATTRIBUTE_UNUSED, xmlElementContentPtr cont, const xmlChar *qname) { - while (cont != NULL) { - if (cont->type == XML_ELEMENT_CONTENT_ELEMENT) { - if (xmlStrEqual(cont->name, qname)) - return(1); - } else if ((cont->type == XML_ELEMENT_CONTENT_OR) && - (cont->c1 != NULL) && - (cont->c1->type == XML_ELEMENT_CONTENT_ELEMENT)){ - if (xmlStrEqual(cont->c1->name, qname)) - return(1); - } else if ((cont->type != XML_ELEMENT_CONTENT_OR) || - (cont->c1 == NULL) || - (cont->c1->type != XML_ELEMENT_CONTENT_PCDATA)){ - /* Internal error !!! */ - xmlGenericError(xmlGenericErrorContext, - "Internal: MIXED struct bad\n"); - break; + const xmlChar *name; + int plen; + name = xmlSplitQName3(qname, &plen); + + if (name == NULL) { + while (cont != NULL) { + if (cont->type == XML_ELEMENT_CONTENT_ELEMENT) { + if ((cont->prefix == NULL) && (xmlStrEqual(cont->name, qname))) + return(1); + } else if ((cont->type == XML_ELEMENT_CONTENT_OR) && + (cont->c1 != NULL) && + (cont->c1->type == XML_ELEMENT_CONTENT_ELEMENT)){ + if ((cont->c1->prefix == NULL) && + (xmlStrEqual(cont->c1->name, qname))) + return(1); + } else if ((cont->type != XML_ELEMENT_CONTENT_OR) || + (cont->c1 == NULL) || + (cont->c1->type != XML_ELEMENT_CONTENT_PCDATA)){ + /* Internal error !!! */ + xmlGenericError(xmlGenericErrorContext, + "Internal: MIXED struct bad\n"); + break; + } + cont = cont->c2; + } + } else { + while (cont != NULL) { + if (cont->type == XML_ELEMENT_CONTENT_ELEMENT) { + if ((cont->prefix != NULL) && + (xmlStrncmp(cont->prefix, qname, plen) == 0) && + (xmlStrEqual(cont->name, name))) + return(1); + } else if ((cont->type == XML_ELEMENT_CONTENT_OR) && + (cont->c1 != NULL) && + (cont->c1->type == XML_ELEMENT_CONTENT_ELEMENT)){ + if ((cont->c1->prefix != NULL) && + (xmlStrncmp(cont->c1->prefix, qname, plen) == 0) && + (xmlStrEqual(cont->c1->name, name))) + return(1); + } else if ((cont->type != XML_ELEMENT_CONTENT_OR) || + (cont->c1 == NULL) || + (cont->c1->type != XML_ELEMENT_CONTENT_PCDATA)){ + /* Internal error !!! */ + xmlGenericError(xmlGenericErrorContext, + "Internal: MIXED struct bad\n"); + break; + } + cont = cont->c2; } - cont = cont->c2; } return(0); }