[libxslt] Precompute XSLT elements after preprocessing



commit af31ef183b0c7032ac312c8217f62e3fa5425250
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Sun Jul 3 14:47:54 2016 +0200

    Precompute XSLT elements after preprocessing
    
    Move the call to xsltStylePreCompute from xsltPrecomputeStylesheet to
    later stages of the parsing process. Rename xsltPrecomputeStylesheet
    to xsltPreprocessStylesheet. This allows to completely ignore contents
    of unknown XSLT elements in forwards-compatible mode.
    
    This is a somewhat dangerous change. If I missed some additional
    locations where xsltStylePreCompute must be called, it might result
    in errors or performance degradation.
    
    Fixes bug #677901:
    
    https://bugzilla.gnome.org/show_bug.cgi?id=677901

 libxslt/attributes.c      |    9 +++++++++
 libxslt/xslt.c            |   15 ++++++++-------
 tests/REC/test-2.5-1.err  |    4 ++--
 tests/general/bug-175.err |    4 ++--
 tests/general/bug-175.xsl |    5 ++++-
 5 files changed, 25 insertions(+), 12 deletions(-)
---
diff --git a/libxslt/attributes.c b/libxslt/attributes.c
index 6c4d0d1..9165ab1 100644
--- a/libxslt/attributes.c
+++ b/libxslt/attributes.c
@@ -473,6 +473,15 @@ xsltParseStylesheetAttributeSet(xsltStylesheetPtr style, xmlNodePtr cur) {
            xsltGenericDebug(xsltGenericDebugContext,
                "add attribute to list %s\n", ncname);
 #endif
+            xsltStylePreCompute(style, child);
+            if (child->children != NULL) {
+#ifdef XSLT_REFACTORED
+                xsltParseSequenceConstructor(XSLT_CCTXT(style),
+                                             child->children);
+#else
+                xsltParseTemplateContent(style, child);
+#endif
+            }
             if (child->psvi == NULL) {
                 xsltTransformError(NULL, style, child,
                     "xsl:attribute-set : internal error, attribute %s not "
diff --git a/libxslt/xslt.c b/libxslt/xslt.c
index 330751a..86feb98 100644
--- a/libxslt/xslt.c
+++ b/libxslt/xslt.c
@@ -3422,7 +3422,7 @@ internal_err:
 #ifdef XSLT_REFACTORED
 #else
 static void
-xsltPrecomputeStylesheet(xsltStylesheetPtr style, xmlNodePtr cur)
+xsltPreprocessStylesheet(xsltStylesheetPtr style, xmlNodePtr cur)
 {
     xmlNodePtr deleteNode, styleelem;
     int internalize = 0;
@@ -3453,7 +3453,7 @@ xsltPrecomputeStylesheet(xsltStylesheetPtr style, xmlNodePtr cur)
        if (deleteNode != NULL) {
 #ifdef WITH_XSLT_DEBUG_BLANKS
            xsltGenericDebug(xsltGenericDebugContext,
-            "xsltPrecomputeStylesheet: removing ignorable blank node\n");
+            "xsltPreprocessStylesheet: removing ignorable blank node\n");
 #endif
            xmlUnlinkNode(deleteNode);
            xmlFreeNode(deleteNode);
@@ -3493,7 +3493,6 @@ xsltPrecomputeStylesheet(xsltStylesheetPtr style, xmlNodePtr cur)
            }
            if (IS_XSLT_ELEM(cur)) {
                exclPrefixes = 0;
-               xsltStylePreCompute(style, cur);
                if (IS_XSLT_NAME(cur, "text")) {
                    for (;exclPrefixes > 0;exclPrefixes--)
                        exclPrefixPop(style);
@@ -3544,7 +3543,7 @@ xsltPrecomputeStylesheet(xsltStylesheetPtr style, xmlNodePtr cur)
             * going back
             */
            if (exclPrefixes > 0) {
-               xsltPrecomputeStylesheet(style, cur->children);
+               xsltPreprocessStylesheet(style, cur->children);
                for (;exclPrefixes > 0;exclPrefixes--)
                    exclPrefixPop(style);
                goto skip_children;
@@ -3615,7 +3614,7 @@ skip_children:
     if (deleteNode != NULL) {
 #ifdef WITH_XSLT_DEBUG_PARSING
        xsltGenericDebug(xsltGenericDebugContext,
-        "xsltPrecomputeStylesheet: removing ignorable blank node\n");
+        "xsltPreprocessStylesheet: removing ignorable blank node\n");
 #endif
        xmlUnlinkNode(deleteNode);
        xmlFreeNode(deleteNode);
@@ -4860,10 +4859,12 @@ xsltParseTemplateContent(xsltStylesheetPtr style, xmlNodePtr templ) {
            delete = NULL;
        }
        if (IS_XSLT_ELEM(cur)) {
+            xsltStylePreCompute(style, cur);
+
            if (IS_XSLT_NAME(cur, "text")) {
                /*
                * TODO: Processing of xsl:text should be moved to
-               *   xsltPrecomputeStylesheet(), since otherwise this
+               *   xsltPreprocessStylesheet(), since otherwise this
                *   will be performed for every multiply included
                *   stylesheet; i.e. this here is not skipped with
                *   the use of the style->nopreproc flag.
@@ -6406,7 +6407,7 @@ xsltParseStylesheetProcess(xsltStylesheetPtr ret, xmlDocPtr doc) {
        ret->literal_result = 1;
     }
     if (!ret->nopreproc) {
-       xsltPrecomputeStylesheet(ret, cur);
+       xsltPreprocessStylesheet(ret, cur);
     }
     if (ret->literal_result == 0) {
        xsltParseStylesheetTop(ret, cur);
diff --git a/tests/REC/test-2.5-1.err b/tests/REC/test-2.5-1.err
index 7fbacdd..70cc3c1 100644
--- a/tests/REC/test-2.5-1.err
+++ b/tests/REC/test-2.5-1.err
@@ -1,4 +1,4 @@
-compilation error: file ./test-2.5-1.xsl line 6 element exciting-new-1.8-feature
-xsltStylePreCompute: unknown xsl:exciting-new-1.8-feature
 compilation error: file ./test-2.5-1.xsl line 2 element stylesheet
 xsl:version: only 1.0 features are supported
+compilation error: file ./test-2.5-1.xsl line 6 element exciting-new-1.8-feature
+xsltStylePreCompute: unknown xsl:exciting-new-1.8-feature
diff --git a/tests/general/bug-175.err b/tests/general/bug-175.err
index 70cddd5..e3ec6fb 100644
--- a/tests/general/bug-175.err
+++ b/tests/general/bug-175.err
@@ -1,6 +1,6 @@
-compilation error: file ./bug-175.xsl line 28 element function
-xsltStylePreCompute: unknown xsl:function
 compilation error: file ./bug-175.xsl line 5 element transform
 xsl:version: only 1.0 features are supported
 compilation error: file ./bug-175.xsl line 28 element function
+xsltStylePreCompute: unknown xsl:function
+compilation error: file ./bug-175.xsl line 28 element function
 xsltParseStylesheetTop: ignoring unknown function element
diff --git a/tests/general/bug-175.xsl b/tests/general/bug-175.xsl
index f25e4c9..8ab9f98 100644
--- a/tests/general/bug-175.xsl
+++ b/tests/general/bug-175.xsl
@@ -25,6 +25,9 @@
       </html>
    </xsl:template>
 
-   <xsl:function name="test:test">YES</xsl:function>
+   <xsl:function name="test:test">
+      <xsl:param name="x"/>
+      <xsl:text>YES</xsl:text>
+   </xsl:function>
 
 </xsl:transform>


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