summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2008-05-13 14:34:37 +0000
committerDaniel Veillard <veillard@src.gnome.org>2008-05-13 14:34:37 +0000
commit970091425f31577eb9f106961331f6013f0b3335 (patch)
treed9501c007c406bb0bc26a519c18371d38d805219
parent2fafb8f6dd28f77cecfdac3fe8cc0328248b05b7 (diff)
downloadlibxslt-970091425f31577eb9f106961331f6013f0b3335.tar.gz
fix the processing of top level elements of stylesheets which are not in
* libxslt/xslt.c libxslt/extensions.c libxslt/extensions.h: fix the processing of top level elements of stylesheets which are not in the XSLT namespace and are not an extension either should fix #529223 * tests/docs/Makefile.am tests/docs/bug-167.xml tests/general/Makefile.am tests/general/bug-167.*: add the test to the regression suite Daniel svn path=/trunk/; revision=1472
-rw-r--r--ChangeLog10
-rw-r--r--libxslt/extensions.c33
-rw-r--r--libxslt/extensions.h9
-rw-r--r--libxslt/xslt.c26
-rw-r--r--tests/docs/Makefile.am1
-rw-r--r--tests/docs/bug-167.xml1
-rw-r--r--tests/general/Makefile.am1
-rw-r--r--tests/general/bug-167.out1
-rw-r--r--tests/general/bug-167.xsl20
9 files changed, 92 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 8eb6bce0..1dccc655 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Tue May 13 16:32:22 CEST 2008 Daniel Veillard <daniel@veillard.com>
+
+ * libxslt/xslt.c libxslt/extensions.c libxslt/extensions.h:
+ fix the processing of top level elements of stylesheets which
+ are not in the XSLT namespace and are not an extension either
+ should fix #529223
+ * tests/docs/Makefile.am tests/docs/bug-167.xml
+ tests/general/Makefile.am tests/general/bug-167.*: add the
+ test to the regression suite
+
Fri May 9 14:30:35 CEST 2008 Daniel Veillard <daniel@veillard.com>
* libxslt/documents.c libxslt/keys.c libxslt/xsltInternals.h
diff --git a/libxslt/extensions.c b/libxslt/extensions.c
index 42d8843f..2c1b239d 100644
--- a/libxslt/extensions.c
+++ b/libxslt/extensions.c
@@ -1115,7 +1115,7 @@ xsltShutdownExts(xsltStylesheetPtr style)
/**
* xsltCheckExtPrefix:
* @style: the stylesheet
- * @URI: the namespace URI (possibly NULL)
+ * @URI: the namespace prefix (possibly NULL)
*
* Check if the given prefix is one of the declared extensions.
* This is intended to be called only at compile-time.
@@ -1173,6 +1173,37 @@ xsltCheckExtPrefix(xsltStylesheetPtr style, const xmlChar * URI)
}
/**
+ * xsltCheckExtURI:
+ * @style: the stylesheet
+ * @URI: the namespace URI (possibly NULL)
+ *
+ * Check if the given prefix is one of the declared extensions.
+ * This is intended to be called only at compile-time.
+ * Called by:
+ * xsltPrecomputeStylesheet() (xslt.c)
+ * xsltParseTemplateContent (xslt.c)
+ *
+ * Returns 1 if this is an extension, 0 otherwise
+ */
+int
+xsltCheckExtURI(xsltStylesheetPtr style, const xmlChar * URI)
+{
+ xsltExtDefPtr cur;
+
+ if ((style == NULL) || (style->nsDefs == NULL))
+ return (0);
+ if (URI == NULL)
+ return (0);
+ cur = (xsltExtDefPtr) style->nsDefs;
+ while (cur != NULL) {
+ if (xmlStrEqual(URI, cur->URI))
+ return (1);
+ cur = cur->next;
+ }
+ return (0);
+}
+
+/**
* xsltRegisterExtModuleFull:
* @URI: URI associated to this module
* @initFunc: the module initialization function
diff --git a/libxslt/extensions.h b/libxslt/extensions.h
index 1036faea..30b7d4c1 100644
--- a/libxslt/extensions.h
+++ b/libxslt/extensions.h
@@ -75,7 +75,7 @@ XSLTPUBFUN int XSLTCALL
xsltRegisterExtModule (const xmlChar *URI,
xsltExtInitFunction initFunc,
xsltExtShutdownFunction shutdownFunc);
-XSLTPUBFUN int XSLTCALL
+XSLTPUBFUN int XSLTCALL
xsltRegisterExtModuleFull
(const xmlChar * URI,
xsltExtInitFunction initFunc,
@@ -83,8 +83,8 @@ XSLTPUBFUN int XSLTCALL
xsltStyleExtInitFunction styleInitFunc,
xsltStyleExtShutdownFunction styleShutdownFunc);
-XSLTPUBFUN int XSLTCALL
- xsltUnregisterExtModule (const xmlChar * URI);
+XSLTPUBFUN int XSLTCALL
+ xsltUnregisterExtModule (const xmlChar * URI);
XSLTPUBFUN void * XSLTCALL
xsltGetExtData (xsltTransformContextPtr ctxt,
@@ -216,6 +216,9 @@ XSLTPUBFUN int XSLTCALL
XSLTPUBFUN int XSLTCALL
xsltCheckExtPrefix (xsltStylesheetPtr style,
const xmlChar *URI);
+XSLTPUBFUN int XSLTCALL
+ xsltCheckExtURI (xsltStylesheetPtr style,
+ const xmlChar *URI);
XSLTPUBFUN int XSLTCALL
xsltInitCtxtExts (xsltTransformContextPtr ctxt);
XSLTPUBFUN void XSLTCALL
diff --git a/libxslt/xslt.c b/libxslt/xslt.c
index 27bcc103..6f76a339 100644
--- a/libxslt/xslt.c
+++ b/libxslt/xslt.c
@@ -3397,7 +3397,7 @@ internal_err:
static void
xsltPrecomputeStylesheet(xsltStylesheetPtr style, xmlNodePtr cur)
{
- xmlNodePtr deleteNode;
+ xmlNodePtr deleteNode, styleelem;
int internalize = 0;
if ((style == NULL) || (cur == NULL))
@@ -3408,6 +3408,14 @@ xsltPrecomputeStylesheet(xsltStylesheetPtr style, xmlNodePtr cur)
internalize = 1;
else
style->internalized = 0;
+
+ if ((cur != NULL) && (IS_XSLT_ELEM(cur)) &&
+ (IS_XSLT_NAME(cur, "stylesheet"))) {
+ styleelem = cur;
+ } else {
+ styleelem = NULL;
+ }
+
/*
* This content comes from the stylesheet
* For stylesheets, the set of whitespace-preserving
@@ -3539,9 +3547,16 @@ xsltPrecomputeStylesheet(xsltStylesheetPtr style, xmlNodePtr cur)
}
/*
- * Skip to next node
+ * Skip to next node. In case of a namespaced element children of
+ * the stylesheet and not in the XSLT namespace and not an extension
+ * element, ignore its content.
*/
- if (cur->children != NULL) {
+ if ((cur->type == XML_ELEMENT_NODE) && (cur->ns != NULL) &&
+ (styleelem != NULL) && (cur->parent == styleelem) &&
+ (!xmlStrEqual(cur->ns->href, XSLT_NAMESPACE)) &&
+ (!xsltCheckExtURI(style, cur->ns->href))) {
+ goto skip_children;
+ } else if (cur->children != NULL) {
if ((cur->children->type != XML_ENTITY_DECL) &&
(cur->children->type != XML_ENTITY_REF_NODE) &&
(cur->children->type != XML_ENTITY_NODE)) {
@@ -3554,7 +3569,7 @@ skip_children:
if (cur->next != NULL) {
cur = cur->next;
continue;
- }
+ }
do {
cur = cur->parent;
@@ -6023,11 +6038,10 @@ xsltParseStylesheetTop(xsltStylesheetPtr style, xmlNodePtr top) {
xmlFree(prop);
}
- cur = top->children;
-
/*
* process xsl:import elements
*/
+ cur = top->children;
while (cur != NULL) {
if (IS_BLANK_NODE(cur)) {
cur = cur->next;
diff --git a/tests/docs/Makefile.am b/tests/docs/Makefile.am
index 727d0814..a261fcb7 100644
--- a/tests/docs/Makefile.am
+++ b/tests/docs/Makefile.am
@@ -165,6 +165,7 @@ EXTRA_DIST = \
bug-164.xml \
bug-165.xml \
bug-166.xml \
+ bug-167.xml \
character.xml \
array.xml \
items.xml
diff --git a/tests/docs/bug-167.xml b/tests/docs/bug-167.xml
new file mode 100644
index 00000000..69d62f2c
--- /dev/null
+++ b/tests/docs/bug-167.xml
@@ -0,0 +1 @@
+<doc/>
diff --git a/tests/general/Makefile.am b/tests/general/Makefile.am
index 4c52d298..106844be 100644
--- a/tests/general/Makefile.am
+++ b/tests/general/Makefile.am
@@ -174,6 +174,7 @@ EXTRA_DIST = \
bug-164.out bug-164.xsl \
bug-165.out bug-165.xsl bug-145.err \
bug-166.out bug-166.xsl \
+ bug-167.out bug-167.xsl \
character.out character.xsl \
character2.out character2.xsl \
itemschoose.out itemschoose.xsl \
diff --git a/tests/general/bug-167.out b/tests/general/bug-167.out
new file mode 100644
index 00000000..54bf7eda
--- /dev/null
+++ b/tests/general/bug-167.out
@@ -0,0 +1 @@
+Hello \ No newline at end of file
diff --git a/tests/general/bug-167.xsl b/tests/general/bug-167.xsl
new file mode 100644
index 00000000..8bff7bfe
--- /dev/null
+++ b/tests/general/bug-167.xsl
@@ -0,0 +1,20 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="1.0">
+
+<xsl:output method="text"/>
+
+<xsl:template match="/">
+ <xsl:text>Hello </xsl:text>
+ <xsl:if test="false()">
+ <xsl:text>world</xsl:text>
+ </xsl:if>
+</xsl:template>
+
+<x:ignore xmlns:x="x">
+<xsl:template match="/">
+ <!--this better not be here!-->
+</xsl:template>
+</x:ignore>
+
+</xsl:stylesheet>
+