rolled back to 2.9.2 because 2.9.4 doesn't work with XML validator
[platform/upstream/libxml2.git] / xpath.c
diff --git a/xpath.c b/xpath.c
index 113bce6..dc41ce6 100644 (file)
--- a/xpath.c
+++ b/xpath.c
@@ -361,14 +361,14 @@ turtle_comparison:
     /*
      * compute depth to root
      */
-    for (depth2 = 0, cur = node2; cur->parent != NULL; cur = cur->parent) {
-       if (cur->parent == node1)
+    for (depth2 = 0, cur = node2;cur->parent != NULL;cur = cur->parent) {
+       if (cur == node1)
            return(1);
        depth2++;
     }
     root = cur;
-    for (depth1 = 0, cur = node1; cur->parent != NULL; cur = cur->parent) {
-       if (cur->parent == node2)
+    for (depth1 = 0, cur = node1;cur->parent != NULL;cur = cur->parent) {
+       if (cur == node2)
            return(-1);
        depth1++;
     }
@@ -639,7 +639,7 @@ xmlXPathErrMemory(xmlXPathContextPtr ctxt, const char *extra)
             xmlChar buf[200];
 
             xmlStrPrintf(buf, 200,
-                         "Memory allocation failed : %s\n",
+                         BAD_CAST "Memory allocation failed : %s\n",
                          extra);
             ctxt->lastError.message = (char *) xmlStrdup(buf);
         } else {
@@ -945,7 +945,7 @@ struct _xmlXPathCompExpr {
     xmlXPathStepOp *steps;     /* ops for computation of this expression */
     int last;                  /* index of last step in expression */
     xmlChar *expr;             /* the expression being computed */
-    xmlDictPtr dict;           /* the dictionary to use if any */
+    xmlDictPtr dict;           /* the dictionnary to use if any */
 #ifdef DEBUG_EVAL_COUNTS
     int nb;
     xmlChar *string;
@@ -3706,7 +3706,7 @@ xmlXPathNodeSetAdd(xmlNodeSetPtr cur, xmlNodePtr val) {
 
     /* @@ with_ns to check whether namespace nodes should be looked at @@ */
     /*
-     * prevent duplicates
+     * prevent duplcates
      */
     for (i = 0;i < cur->nodeNr;i++)
         if (cur->nodeTab[i] == val) return(0);
@@ -7933,14 +7933,14 @@ xmlXPathNextDescendant(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
 xmlNodePtr
 xmlXPathNextDescendantOrSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
     if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
-    if (cur == NULL)
+    if (cur == NULL) {
+       if (ctxt->context->node == NULL)
+           return(NULL);
+       if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) ||
+           (ctxt->context->node->type == XML_NAMESPACE_DECL))
+           return(NULL);
         return(ctxt->context->node);
-
-    if (ctxt->context->node == NULL)
-        return(NULL);
-    if ((ctxt->context->node->type == XML_ATTRIBUTE_NODE) ||
-        (ctxt->context->node->type == XML_NAMESPACE_DECL))
-        return(NULL);
+    }
 
     return(xmlXPathNextDescendant(ctxt, cur));
 }
@@ -8390,7 +8390,7 @@ xmlNodePtr
 xmlXPathNextNamespace(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) {
     if ((ctxt == NULL) || (ctxt->context == NULL)) return(NULL);
     if (ctxt->context->node->type != XML_ELEMENT_NODE) return(NULL);
-    if (cur == NULL) {
+    if (ctxt->context->tmpNsList == NULL && cur != (xmlNodePtr) xmlXPathXMLNamespace) {
         if (ctxt->context->tmpNsList != NULL)
            xmlFree(ctxt->context->tmpNsList);
        ctxt->context->tmpNsList =
@@ -9996,7 +9996,7 @@ xmlXPathParseNameComplex(xmlXPathParserContextPtr ctxt, int qualified) {
         (c == '[') || (c == ']') || (c == '@') || /* accelerators */
         (c == '*') || /* accelerators */
        (!IS_LETTER(c) && (c != '_') &&
-         ((!qualified) || (c != ':')))) {
+         ((qualified) && (c != ':')))) {
        return(NULL);
     }
 
@@ -12379,6 +12379,11 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt,
                     STRANGE
                    goto error;
                 case NODE_TEST_TYPE:
+                   /*
+                   * TODO: Don't we need to use
+                   *  xmlXPathNodeSetAddNs() for namespace nodes here?
+                   *  Surprisingly, some c14n tests fail, if we do this.
+                   */
                    if (type == NODE_TYPE_NODE) {
                        switch (cur->type) {
                            case XML_DOCUMENT_NODE:
@@ -12392,17 +12397,9 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt,
                            case XML_COMMENT_NODE:
                            case XML_CDATA_SECTION_NODE:
                            case XML_TEXT_NODE:
+                           case XML_NAMESPACE_DECL:
                                XP_TEST_HIT
                                break;
-                           case XML_NAMESPACE_DECL: {
-                               if (axis == AXIS_NAMESPACE) {
-                                   XP_TEST_HIT_NS
-                               } else {
-                                   hasNsNodes = 1;
-                                   XP_TEST_HIT
-                               }
-                               break;
-                            }
                            default:
                                break;
                        }
@@ -12694,14 +12691,6 @@ error:
     * Reset the context node.
     */
     xpctxt->node = oldContextNode;
-    /*
-    * When traversing the namespace axis in "toBool" mode, it's
-    * possible that tmpNsList wasn't freed.
-    */
-    if (xpctxt->tmpNsList != NULL) {
-        xmlFree(xpctxt->tmpNsList);
-        xpctxt->tmpNsList = NULL;
-    }
 
 #ifdef DEBUG_STEP
     xmlGenericError(xmlGenericErrorContext,
@@ -14795,10 +14784,6 @@ xmlXPathOptimizeExpression(xmlXPathCompExprPtr comp, xmlXPathStepOpPtr op)
        }
     }
 
-    /* OP_VALUE has invalid ch1. */
-    if (op->op == XPATH_OP_VALUE)
-        return;
-
     /* Recurse */
     if (op->ch1 != -1)
         xmlXPathOptimizeExpression(comp, &comp->steps[op->ch1]);