From 0438375d2e6be47d0179826271081ae64df94f8b Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Sun, 8 Jul 2001 14:27:15 +0000 Subject: [PATCH] fix the name() bug for elements in the default namespace reported by * xpath.c: fix the name() bug for elements in the default namespace reported by Charlie Bozeman Daniel --- ChangeLog | 5 +++++ xpath.c | 65 ++++++++++++++++++++++++++++++------------------------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 10b84684..bc1b20ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Jul 8 16:26:00 CEST 2001 Daniel Veillard + + * xpath.c: fix the name() bug for elements in the default + namespace reported by Charlie Bozeman + Sun Jul 8 15:11:05 CEST 2001 Daniel Veillard * SAX.c parser.c testXPath.c xpath.c: trying to fix #56948, this diff --git a/xpath.c b/xpath.c index 307bae2d..1fb3eea4 100644 --- a/xpath.c +++ b/xpath.c @@ -4815,47 +4815,52 @@ xmlXPathNamespaceURIFunction(xmlXPathParserContextPtr ctxt, int nargs) { * returned. */ static void -xmlXPathNameFunction(xmlXPathParserContextPtr ctxt, int nargs) { +xmlXPathNameFunction(xmlXPathParserContextPtr ctxt, int nargs) +{ xmlXPathObjectPtr cur; if (nargs == 0) { - valuePush(ctxt, xmlXPathNewNodeSet(ctxt->context->node)); - nargs = 1; + valuePush(ctxt, xmlXPathNewNodeSet(ctxt->context->node)); + nargs = 1; } CHECK_ARITY(1); - if ((ctxt->value == NULL) || - ((ctxt->value->type != XPATH_NODESET) && - (ctxt->value->type != XPATH_XSLT_TREE))) - XP_ERROR(XPATH_INVALID_TYPE); + if ((ctxt->value == NULL) || + ((ctxt->value->type != XPATH_NODESET) && + (ctxt->value->type != XPATH_XSLT_TREE))) + XP_ERROR(XPATH_INVALID_TYPE); cur = valuePop(ctxt); if ((cur->nodesetval == NULL) || (cur->nodesetval->nodeNr == 0)) { - valuePush(ctxt, xmlXPathNewCString("")); + valuePush(ctxt, xmlXPathNewCString("")); } else { - int i = 0; /* Should be first in document order !!!!! */ + int i = 0; /* Should be first in document order !!!!! */ - switch (cur->nodesetval->nodeTab[i]->type) { - case XML_ELEMENT_NODE: - case XML_ATTRIBUTE_NODE: - if (cur->nodesetval->nodeTab[i]->ns == NULL) - valuePush(ctxt, xmlXPathNewString( - cur->nodesetval->nodeTab[i]->name)); - - else { - char name[2000]; - snprintf(name, sizeof(name), "%s:%s", - (char *) cur->nodesetval->nodeTab[i]->ns->prefix, - (char *) cur->nodesetval->nodeTab[i]->name); - name[sizeof(name) - 1] = 0; - valuePush(ctxt, xmlXPathNewCString(name)); - } - break; - default: - valuePush(ctxt, - xmlXPathNewNodeSet(cur->nodesetval->nodeTab[i])); - xmlXPathLocalNameFunction(ctxt, 1); - } + switch (cur->nodesetval->nodeTab[i]->type) { + case XML_ELEMENT_NODE: + case XML_ATTRIBUTE_NODE: + if ((cur->nodesetval->nodeTab[i]->ns == NULL) || + (cur->nodesetval->nodeTab[i]->ns->prefix == NULL)) + valuePush(ctxt, + xmlXPathNewString(cur->nodesetval-> + nodeTab[i]->name)); + + else { + char name[2000]; + + snprintf(name, sizeof(name), "%s:%s", + (char *) cur->nodesetval->nodeTab[i]->ns-> + prefix, + (char *) cur->nodesetval->nodeTab[i]->name); + name[sizeof(name) - 1] = 0; + valuePush(ctxt, xmlXPathNewCString(name)); + } + break; + default: + valuePush(ctxt, + xmlXPathNewNodeSet(cur->nodesetval->nodeTab[i])); + xmlXPathLocalNameFunction(ctxt, 1); + } } xmlXPathFreeObject(cur); }