summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@redhat.com>2012-09-07 14:27:16 +0800
committerDaniel Veillard <veillard@redhat.com>2012-09-07 14:27:16 +0800
commit0ae3194eb58d954d0896ef05e3dacf76350a8bc2 (patch)
treee74807260649e5699ca8040e040895aa5f8c7d3e
parent85c621da5afac3076c0de2e9aacec1252ad582ff (diff)
downloadlibxslt-0ae3194eb58d954d0896ef05e3dacf76350a8bc2.tar.gz
libxslt-0ae3194eb58d954d0896ef05e3dacf76350a8bc2.tar.bz2
libxslt-0ae3194eb58d954d0896ef05e3dacf76350a8bc2.zip
Report errors on variable use in key
For https://bugzilla.gnome.org/show_bug.cgi?id=680938 Variables are forbidden for match or use values of keys * libxslt/xsltutils.c libxslt/xsltutils.h: allows to add flags to XPath expression compilation * libxslt/keys.c: add the XML_XPATH_NOVAR if defined (recent libxml2) * libxslt/pattern.c: add a missing xpath.h include to make sure the defintiion is found there too
-rw-r--r--libxslt/keys.c9
-rw-r--r--libxslt/pattern.c1
-rw-r--r--libxslt/xsltutils.c22
-rw-r--r--libxslt/xsltutils.h4
4 files changed, 34 insertions, 2 deletions
diff --git a/libxslt/keys.c b/libxslt/keys.c
index d28aea67..d85e12c7 100644
--- a/libxslt/keys.c
+++ b/libxslt/keys.c
@@ -21,6 +21,7 @@
#include <libxml/xmlerror.h>
#include <libxml/parserInternals.h>
#include <libxml/xpathInternals.h>
+#include <libxml/xpath.h>
#include "xslt.h"
#include "xsltInternals.h"
#include "xsltutils.h"
@@ -356,14 +357,22 @@ xsltAddKey(xsltStylesheetPtr style, const xmlChar *name,
* Maybe a search for "$", if it occurs outside of quotation
* marks, could be sufficient.
*/
+#ifdef XML_XPATH_NOVAR
+ key->comp = xsltXPathCompileFlags(style, pattern, XML_XPATH_NOVAR);
+#else
key->comp = xsltXPathCompile(style, pattern);
+#endif
if (key->comp == NULL) {
xsltTransformError(NULL, style, inst,
"xsl:key : XPath pattern compilation failed '%s'\n",
pattern);
if (style != NULL) style->errors++;
}
+#ifdef XML_XPATH_NOVAR
+ key->usecomp = xsltXPathCompileFlags(style, use, XML_XPATH_NOVAR);
+#else
key->usecomp = xsltXPathCompile(style, use);
+#endif
if (key->usecomp == NULL) {
xsltTransformError(NULL, style, inst,
"xsl:key : XPath pattern compilation failed '%s'\n",
diff --git a/libxslt/pattern.c b/libxslt/pattern.c
index a6140cba..fc6455f7 100644
--- a/libxslt/pattern.c
+++ b/libxslt/pattern.c
@@ -25,6 +25,7 @@
#include <libxml/hash.h>
#include <libxml/xmlerror.h>
#include <libxml/parserInternals.h>
+#include <libxml/xpath.h>
#include "xslt.h"
#include "xsltInternals.h"
#include "xsltutils.h"
diff --git a/libxslt/xsltutils.c b/libxslt/xsltutils.c
index bc942668..d239162e 100644
--- a/libxslt/xsltutils.c
+++ b/libxslt/xsltutils.c
@@ -2273,9 +2273,10 @@ xsltGetProfileInformation(xsltTransformContextPtr ctxt)
************************************************************************/
/**
- * xsltXPathCompile:
+ * xsltXPathCompileFlags:
* @style: the stylesheet
* @str: the XPath expression
+ * @flags: extra compilation flags to pass down to libxml2 XPath
*
* Compile an XPath expression
*
@@ -2283,7 +2284,7 @@ xsltGetProfileInformation(xsltTransformContextPtr ctxt)
* the caller has to free the object.
*/
xmlXPathCompExprPtr
-xsltXPathCompile(xsltStylesheetPtr style, const xmlChar *str) {
+xsltXPathCompileFlags(xsltStylesheetPtr style, const xmlChar *str, int flags) {
xmlXPathContextPtr xpathCtxt;
xmlXPathCompExprPtr ret;
@@ -2315,6 +2316,8 @@ xsltXPathCompile(xsltStylesheetPtr style, const xmlChar *str) {
if (xpathCtxt == NULL)
return NULL;
}
+ xpathCtxt->flags = flags;
+
/*
* Compile the expression.
*/
@@ -2335,6 +2338,21 @@ xsltXPathCompile(xsltStylesheetPtr style, const xmlChar *str) {
return(ret);
}
+/**
+ * xsltXPathCompile:
+ * @style: the stylesheet
+ * @str: the XPath expression
+ *
+ * Compile an XPath expression
+ *
+ * Returns the xmlXPathCompExprPtr resulting from the compilation or NULL.
+ * the caller has to free the object.
+ */
+xmlXPathCompExprPtr
+xsltXPathCompile(xsltStylesheetPtr style, const xmlChar *str) {
+ return(xsltXPathCompileFlags(style, str, 0));
+}
+
/************************************************************************
* *
* Hooks for the debugger *
diff --git a/libxslt/xsltutils.h b/libxslt/xsltutils.h
index c986a9c7..15da89c6 100644
--- a/libxslt/xsltutils.h
+++ b/libxslt/xsltutils.h
@@ -242,6 +242,10 @@ XSLTPUBFUN int XSLTCALL
XSLTPUBFUN xmlXPathCompExprPtr XSLTCALL
xsltXPathCompile (xsltStylesheetPtr style,
const xmlChar *str);
+XSLTPUBFUN xmlXPathCompExprPtr XSLTCALL
+ xsltXPathCompileFlags (xsltStylesheetPtr style,
+ const xmlChar *str,
+ int flags);
/*
* Profiling.