[libxml2] Fix namespace::node() XPath expression



commit f39fd66ea768802665e0a010f4be408ef9c69bcf
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Wed Apr 27 03:01:16 2016 +0200

    Fix namespace::node() XPath expression
    
    Make sure that xmlXPathNodeSetAddNs is called for namespace nodes when
    matched with a namespace::node() step. This correctly sets the parent
    of namespace nodes. Note that xmlXPathNodeSetAddNs must only be called
    if working on the namespace axis. Otherwise, the context node is not
    the parent of the namespace node and the standard XP_TEST_HIT macro
    must be invoked. This explains the errors in the C14N tests that the
    old TODO comment mentioned.

 result/XPath/tests/nssimple |    7 +++++++
 test/XPath/docs/ns          |    3 +++
 test/XPath/tests/nssimple   |    1 +
 xpath.c                     |   14 ++++++++------
 4 files changed, 19 insertions(+), 6 deletions(-)
---
diff --git a/result/XPath/tests/nssimple b/result/XPath/tests/nssimple
new file mode 100644
index 0000000..ce63811
--- /dev/null
+++ b/result/XPath/tests/nssimple
@@ -0,0 +1,7 @@
+
+========================
+Expression: /doc/elem/namespace::node()/..
+Object is a Node Set :
+Set contains 1 nodes:
+1  ELEMENT elem
+    namespace ns1 href=ns1
diff --git a/test/XPath/docs/ns b/test/XPath/docs/ns
new file mode 100644
index 0000000..df4789f
--- /dev/null
+++ b/test/XPath/docs/ns
@@ -0,0 +1,3 @@
+<doc>
+  <elem xmlns:ns1="ns1"/>
+</doc>
diff --git a/test/XPath/tests/nssimple b/test/XPath/tests/nssimple
new file mode 100644
index 0000000..5f58fc6
--- /dev/null
+++ b/test/XPath/tests/nssimple
@@ -0,0 +1 @@
+/doc/elem/namespace::node()/..
diff --git a/xpath.c b/xpath.c
index 7d03454..6b92e7d 100644
--- a/xpath.c
+++ b/xpath.c
@@ -12379,11 +12379,6 @@ 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:
@@ -12397,9 +12392,16 @@ 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 {
+                                   XP_TEST_HIT
+                               }
+                               break;
+                            }
                            default:
                                break;
                        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]