[libxslt] Report errors on variable use in key



commit 0ae3194eb58d954d0896ef05e3dacf76350a8bc2
Author: Daniel Veillard <veillard redhat com>
Date:   Fri Sep 7 14:27:16 2012 +0800

    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

 libxslt/keys.c      |    9 +++++++++
 libxslt/pattern.c   |    1 +
 libxslt/xsltutils.c |   22 ++++++++++++++++++++--
 libxslt/xsltutils.h |    4 ++++
 4 files changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/libxslt/keys.c b/libxslt/keys.c
index d28aea6..d85e12c 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 a6140cb..fc6455f 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 bc94266..d239162 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 c986a9c..15da89c 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.



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