summaryrefslogtreecommitdiff
path: root/libexslt/saxon.c
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2016-06-22 14:10:16 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2016-06-22 14:10:46 +0900
commiteffb43a066e70763fa89eb7142b7cb7b428694ad (patch)
treed9712da186814a92d207016209bb7e19d7db5596 /libexslt/saxon.c
parent195f644cf7b5e93208b033fa7c5501c41cf82f59 (diff)
downloadlibxslt-effb43a066e70763fa89eb7142b7cb7b428694ad.tar.gz
libxslt-effb43a066e70763fa89eb7142b7cb7b428694ad.tar.bz2
libxslt-effb43a066e70763fa89eb7142b7cb7b428694ad.zip
Imported Upstream version 1.1.29upstream/1.1.29
Change-Id: I7d894ba27f8f8e886dbcece3bb3df8e69059cae9 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'libexslt/saxon.c')
-rw-r--r--libexslt/saxon.c53
1 files changed, 35 insertions, 18 deletions
diff --git a/libexslt/saxon.c b/libexslt/saxon.c
index e92ba8d0..7a2f63be 100644
--- a/libexslt/saxon.c
+++ b/libexslt/saxon.c
@@ -101,9 +101,7 @@ exsltSaxonExpressionFunction (xmlXPathParserContextPtr ctxt, int nargs) {
ret = xmlXPathCompile(arg);
if (ret == NULL) {
xmlFree(arg);
- xsltGenericError(xsltGenericErrorContext,
- "{%s}:%s: argument is not an XPath expression\n",
- ctxt->context->functionURI, ctxt->context->function);
+ xmlXPathSetError(ctxt, XPATH_EXPR_ERROR);
return;
}
xmlHashAddEntry(hash, arg, (void *) ret);
@@ -147,6 +145,10 @@ exsltSaxonEvalFunction (xmlXPathParserContextPtr ctxt, int nargs) {
expr = (xmlXPathCompExprPtr) xmlXPathPopExternal(ctxt);
ret = xmlXPathCompiledEval(expr, ctxt->context);
+ if (ret == NULL) {
+ xmlXPathSetError(ctxt, XPATH_EXPR_ERROR);
+ return;
+ }
valuePush(ctxt, ret);
}
@@ -227,11 +229,12 @@ exsltSaxonSystemIdFunction(xmlXPathParserContextPtr ctxt, int nargs)
static void
exsltSaxonLineNumberFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlNodePtr cur = NULL;
+ xmlXPathObjectPtr obj = NULL;
+ long lineNo = -1;
if (nargs == 0) {
cur = ctxt->context->node;
} else if (nargs == 1) {
- xmlXPathObjectPtr obj;
xmlNodeSetPtr nodelist;
int i;
@@ -244,18 +247,14 @@ exsltSaxonLineNumberFunction(xmlXPathParserContextPtr ctxt, int nargs) {
obj = valuePop(ctxt);
nodelist = obj->nodesetval;
- if ((nodelist == NULL) || (nodelist->nodeNr <= 0)) {
- xmlXPathFreeObject(obj);
- valuePush(ctxt, xmlXPathNewFloat(-1));
- return;
- }
- cur = nodelist->nodeTab[0];
- for (i = 1;i < nodelist->nodeNr;i++) {
- int ret = xmlXPathCmpNodes(cur, nodelist->nodeTab[i]);
- if (ret == -1)
- cur = nodelist->nodeTab[i];
- }
- xmlXPathFreeObject(obj);
+ if ((nodelist != NULL) && (nodelist->nodeNr > 0)) {
+ cur = nodelist->nodeTab[0];
+ for (i = 1;i < nodelist->nodeNr;i++) {
+ int ret = xmlXPathCmpNodes(cur, nodelist->nodeTab[i]);
+ if (ret == -1)
+ cur = nodelist->nodeTab[i];
+ }
+ }
} else {
xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL,
"saxon:line-number() : invalid number of args %d\n",
@@ -264,8 +263,26 @@ exsltSaxonLineNumberFunction(xmlXPathParserContextPtr ctxt, int nargs) {
return;
}
- valuePush(ctxt, xmlXPathNewFloat(xmlGetLineNo(cur)));
- return;
+ if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL)) {
+ /*
+ * The XPath module sets the owner element of a ns-node on
+ * the ns->next field.
+ */
+ cur = (xmlNodePtr) ((xmlNsPtr) cur)->next;
+ if (cur == NULL || cur->type != XML_ELEMENT_NODE) {
+ xsltGenericError(xsltGenericErrorContext,
+ "Internal error in exsltSaxonLineNumberFunction: "
+ "Cannot retrieve the doc of a namespace node.\n");
+ cur = NULL;
+ }
+ }
+
+ if (cur != NULL)
+ lineNo = xmlGetLineNo(cur);
+
+ valuePush(ctxt, xmlXPathNewFloat(lineNo));
+
+ xmlXPathFreeObject(obj);
}
/**