From 68e9e74af85ebbc30781787f247c361bc85adfa0 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Sat, 16 Nov 2002 15:35:11 +0000 Subject: [PATCH] fixing #96925 wich was also dependant on the processing of parsed * parser.c xpath.c: fixing #96925 wich was also dependant on the processing of parsed entities, and XPath computation on sustitued entities. * testXPath.c: make sure entities are substitued. Daniel --- ChangeLog | 7 ++++++ parser.c | 71 ++++++++++++++++++++++++----------------------------- testXPath.c | 1 + xpath.c | 26 +++++++++++++++++--- 4 files changed, 62 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index a6b89b62..c4f090dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat Nov 16 16:30:25 CET 2002 Daniel Veillard + + * parser.c xpath.c: fixing #96925 wich was also dependant on the + processing of parsed entities, and XPath computation on sustitued + entities. + * testXPath.c: make sure entities are substitued. + Fri Nov 15 16:22:54 CET 2002 Daniel Veillard * parser.c: fixed #96594, which was totally dependant on the diff --git a/parser.c b/parser.c index 6fa4d0be..ca56c1d8 100644 --- a/parser.c +++ b/parser.c @@ -5456,6 +5456,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) { } else { while (list != NULL) { list->parent = (xmlNodePtr) ctxt->node; + list->doc = ctxt->myDoc; if (list->next == NULL) ent->last = list; list = list->next; @@ -9767,9 +9768,9 @@ static int xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt, const xmlChar *string, void *user_data, xmlNodePtr *lst) { xmlParserCtxtPtr ctxt; - xmlDocPtr newDoc; + xmlDocPtr newDoc = NULL; xmlSAXHandlerPtr oldsax = NULL; - xmlNodePtr content; + xmlNodePtr content = NULL; int size; int ret = 0; @@ -9794,32 +9795,28 @@ xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt, oldsax = ctxt->sax; ctxt->sax = oldctxt->sax; - newDoc = xmlNewDoc(BAD_CAST "1.0"); - if (newDoc == NULL) { - ctxt->sax = oldsax; - xmlFreeParserCtxt(ctxt); - return(-1); - } - if (oldctxt->myDoc != NULL) { - newDoc->intSubset = oldctxt->myDoc->intSubset; - newDoc->extSubset = oldctxt->myDoc->extSubset; - } - newDoc->children = xmlNewDocNode(newDoc, NULL, BAD_CAST "pseudoroot", NULL); - if (newDoc->children == NULL) { - ctxt->sax = oldsax; - xmlFreeParserCtxt(ctxt); - newDoc->intSubset = NULL; - newDoc->extSubset = NULL; - xmlFreeDoc(newDoc); - return(-1); - } - nodePush(ctxt, newDoc->children); if (oldctxt->myDoc == NULL) { - ctxt->myDoc = oldctxt->myDoc; - } else { + newDoc = xmlNewDoc(BAD_CAST "1.0"); + if (newDoc == NULL) { + ctxt->sax = oldsax; + xmlFreeParserCtxt(ctxt); + return(-1); + } ctxt->myDoc = newDoc; - newDoc->children->doc = newDoc; + } else { + ctxt->myDoc = oldctxt->myDoc; + content = ctxt->myDoc->children; } + ctxt->myDoc->children = xmlNewDocNode(newDoc, NULL, + BAD_CAST "pseudoroot", NULL); + if (ctxt->myDoc->children == NULL) { + ctxt->sax = oldsax; + xmlFreeParserCtxt(ctxt); + if (newDoc != NULL) + xmlFreeDoc(newDoc); + return(-1); + } + nodePush(ctxt, ctxt->myDoc->children); ctxt->instate = XML_PARSER_CONTENT; ctxt->depth = oldctxt->depth + 1; @@ -9829,14 +9826,7 @@ xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt, ctxt->validate = 0; ctxt->loadsubset = oldctxt->loadsubset; - if (ctxt->myDoc != NULL) { - content = ctxt->myDoc->children; - ctxt->myDoc->children = NULL; - xmlParseContent(ctxt); - ctxt->myDoc->children = content; - } else { - xmlParseContent(ctxt); - } + xmlParseContent(ctxt); if ((RAW == '<') && (NXT(1) == '/')) { ctxt->errNo = XML_ERR_NOT_WELL_BALANCED; if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) @@ -9852,7 +9842,7 @@ xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt, ctxt->wellFormed = 0; ctxt->disableSAX = 1; } - if (ctxt->node != newDoc->children) { + if (ctxt->node != ctxt->myDoc->children) { ctxt->errNo = XML_ERR_NOT_WELL_BALANCED; if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) ctxt->sax->error(ctxt->userData, @@ -9877,20 +9867,23 @@ xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt, * Return the newly created nodeset after unlinking it from * they pseudo parent. */ - cur = newDoc->children->children; + cur = ctxt->myDoc->children->children; *lst = cur; while (cur != NULL) { cur->parent = NULL; cur = cur->next; } - newDoc->children->children = NULL; + ctxt->myDoc->children->children = NULL; + } + if (ctxt->myDoc != NULL) { + xmlFreeNode(ctxt->myDoc->children); + ctxt->myDoc->children = content; } ctxt->sax = oldsax; xmlFreeParserCtxt(ctxt); - newDoc->intSubset = NULL; - newDoc->extSubset = NULL; - xmlFreeDoc(newDoc); + if (newDoc != NULL) + xmlFreeDoc(newDoc); return(ret); } diff --git a/testXPath.c b/testXPath.c index 98f482d9..8d138084 100644 --- a/testXPath.c +++ b/testXPath.c @@ -171,6 +171,7 @@ int main(int argc, char **argv) { if (valid != 0) xmlDoValidityCheckingDefaultValue = 1; xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS; xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS; + xmlSubstituteEntitiesDefaultValue = 1; if (nocdata != 0) { xmlDefaultSAXHandlerInit(); xmlDefaultSAXHandler.cdataBlock = NULL; diff --git a/xpath.c b/xpath.c index 5da280f7..28c8a365 100644 --- a/xpath.c +++ b/xpath.c @@ -1367,6 +1367,10 @@ xmlXPathCmpNodes(xmlNodePtr node1, xmlNodePtr node2) { if (node1 == node2->next) return(-1); +#if 0 + Unfortunately this does not work. Line number in entities reset + to 1 within the entity :-( + /* * Speedup using line numbers if availble. */ @@ -1381,7 +1385,7 @@ xmlXPathCmpNodes(xmlNodePtr node1, xmlNodePtr node2) { if (l1 > l2) return(-1); } - +#endif /* * compute depth to root */ @@ -5169,13 +5173,27 @@ xmlXPathNextDescendant(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { } if (cur->children != NULL) { - if (cur->children->type != XML_ENTITY_DECL) - return(cur->children); + /* + * Do not descend on entities declarations + */ + if (cur->children->type != XML_ENTITY_DECL) { + cur = cur->children; + /* + * Skip DTDs + */ + if (cur->type != XML_DTD_NODE) + return(cur); + } } if (cur == ctxt->context->node) return(NULL); - if (cur->next != NULL) return(cur->next); + while (cur->next != NULL) { + cur = cur->next; + if ((cur->type != XML_ENTITY_DECL) && + (cur->type != XML_DTD_NODE)) + return(cur); + } do { cur = cur->parent;