Fixed a difference in processing of xsl:value-of and xsl:text wrt to
authorKasimier T. Buchcik <kbuchcik@src.gnome.org>
Wed, 31 May 2006 20:39:42 +0000 (20:39 +0000)
committerKasimier T. Buchcik <kbuchcik@src.gnome.org>
Wed, 31 May 2006 20:39:42 +0000 (20:39 +0000)
* libxslt/transform.c: Fixed a difference in processing of
  xsl:value-of and  xsl:text wrt to merging of strings of
  output-escaped text-nodes. This difference made the
  optimized string-merging mechanism run out of sync, which
  led to segfaults in subsequent string reallocations. See
  bug #343411, reported by Grzegorz Kaczor.
* xslt.c: Added check for ctxt->internalized when we parse
  xsl:text and internalize the strings.

ChangeLog
libxslt/transform.c
libxslt/xslt.c

index 52f1eab..db4cd52 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Wed May 31 22:32:44 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
+
+       * libxslt/transform.c: Fixed a difference in processing of
+         xsl:value-of and  xsl:text wrt to merging of strings of
+         output-escaped text-nodes. This difference made the
+         optimized string-merging mechanism run out of sync, which
+         led to segfaults in subsequent string reallocations. See
+         bug #343411, reported by Grzegorz Kaczor.
+       * xslt.c: Added check for ctxt->internalized when we parse
+         xsl:text and internalize the strings.
+
 Mon May 22 10:32:57 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
 
        * libxslt/attributes.c libxslt/documents.c
index 0f0fa8a..88df88f 100644 (file)
@@ -709,31 +709,48 @@ xsltCopyText(xsltTransformContextPtr ctxt, xmlNodePtr target,
         ((target->ns != NULL) &&
          (xmlHashLookup2(ctxt->style->cdataSection,
                          target->name, target->ns->href) != NULL)))) {
-       /* OPTIMIZE TODO: xsltCopyText() is also used for attribute content. 
-        * nodes which must be output as CDATA due to the stylesheet
-        */
+       /* 
+       * OPTIMIZE TODO: xsltCopyText() is also used for attribute content.     
+       */
+       /*
+       * TODO: Since this doesn't merge adjacent CDATA-section nodes,
+       * we'll get: <![CDATA[x]]><!CDATA[y]]>.
+       */
        copy = xmlNewCDataBlock(ctxt->output, cur->content,
                                xmlStrlen(cur->content));
        ctxt->lasttext = NULL;
-    } else if ((target != NULL) && (target->last != NULL) &&
-           (target->last->type == XML_TEXT_NODE) &&
-           (target->last->name == xmlStringText) &&
-           (cur->name != xmlStringTextNoenc)) {
+    } else if ((target != NULL) &&
+       (target->last != NULL) &&
+       /* both escaped or both non-escaped text-nodes */
+       (((target->last->type == XML_TEXT_NODE) &&
+       (target->last->name == cur->name)) ||
+        /* non-escaped text nodes and CDATA-section nodes */
+       (((target->last->type == XML_CDATA_SECTION_NODE) &&
+       (cur->name == xmlStringTextNoenc)))))
+    {
        /*
         * we are appending to an existing text node
         */
        return(xsltAddTextString(ctxt, target->last, cur->content,
-                                xmlStrlen(cur->content)));
-    } else if ((interned) && (target != NULL) && (target->doc != NULL) &&
-               (target->doc->dict == ctxt->dict)) {
+           xmlStrlen(cur->content)));
+    } else if ((interned) && (target != NULL) &&
+       (target->doc != NULL) &&
+       (target->doc->dict == ctxt->dict))
+    {        
+       /*
+       * TODO: DO we want to use this also for "text" output?
+       */
         copy = xmlNewTextLen(NULL, 0);
        if (copy == NULL)
-           return NULL;
+           return NULL;        
        if (cur->name == xmlStringTextNoenc)
            copy->name = xmlStringTextNoenc;
-       /* OPTIMIZE TODO: get rid of xmlDictOwns() in safe cases; e.g. attribute values don't need the lookup
-        * Must confirm that content is in dict
-        * (bug 302821)
+       
+       /* OPTIMIZE TODO: get rid of xmlDictOwns() in safe cases;
+        *  e.g. attribute values don't need the lookup.
+        *
+        * Must confirm that content is in dict (bug 302821)
+        * TODO: Check if bug 302821 still applies here.
         */
        if (xmlDictOwns(ctxt->dict, cur->content))
            copy->content = cur->content;
index 513fbf7..ab73975 100644 (file)
@@ -4575,7 +4575,8 @@ xsltParseTemplateContent(xsltStylesheetPtr style, xmlNodePtr templ) {
                    if (text == NULL) {
                        text = cur->children;
                        while (text != NULL) {
-                           if ((text->content != NULL) &&
+                           if ((style->internalized) &&
+                               (text->content != NULL) &&
                                (!xmlDictOwns(style->dict, text->content))) {
 
                                /*