Fixed bug #302020, reported by Thomas Blatter.
authorKasimier T. Buchcik <kbuchcik@src.gnome.org>
Mon, 15 May 2006 20:35:12 +0000 (20:35 +0000)
committerKasimier T. Buchcik <kbuchcik@src.gnome.org>
Mon, 15 May 2006 20:35:12 +0000 (20:35 +0000)
* libxslt/namespaces.c libxslt/attributes.c:
  Fixed bug #302020, reported by Thomas Blatter.

ChangeLog
libxslt/attributes.c
libxslt/namespaces.c

index ea37ba9..6f13041 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon May 15 22:32:13 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
+
+       * libxslt/namespaces.c libxslt/attributes.c:
+         Fixed bug #302020, reported by Thomas Blatter.
+
 Fri May 12 23:23:06 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
 
        * libxslt/documents.c libxslt/namespaces.c
index 849b2f6..d72f41d 100644 (file)
@@ -708,7 +708,10 @@ xsltAttributeInternal(xsltTransformContextPtr ctxt, xmlNodePtr node,
         namespace = xsltEvalAttrValueTemplate(ctxt, inst,
                                               (const xmlChar *)
                                               "namespace", XSLT_NAMESPACE);
-        if (namespace != NULL) {
+       /*
+       * This fixes bug #302020: check also for the empty string.
+       */
+        if ((namespace != NULL) && (*namespace != 0)) {
             ns = xsltGetSpecialNamespace(ctxt, inst, namespace, prefix,
                                          ctxt->insert);
             xmlFree(namespace);
@@ -746,7 +749,7 @@ xsltAttributeInternal(xsltTransformContextPtr ctxt, xmlNodePtr node,
        if (attr != NULL)
            return;
     }
-    value = xsltEvalTemplateString(ctxt, node, inst);
+    value = xsltEvalTemplateString(ctxt, node, inst); /* OPTIMIZE TODO: expensive! */
     if (value == NULL) {
         if (ns) {
             attr = xmlSetNsProp(ctxt->insert, ns, name,
index b9bedc2..8f783bb 100644 (file)
@@ -509,10 +509,34 @@ xsltGetSpecialNamespace(xsltTransformContextPtr ctxt, xmlNodePtr cur,
        return(NULL);
 
     if ((prefix == NULL) && (URI[0] == 0)) {
+       /*
+       * This tries to "undeclare" a default namespace.
+       * This fixes a part of bug #302020:
+       *  1) Added a check whether the queried ns-decl
+       *     is already an "undeclaration" of the default
+       *     namespace.
+       *  2) This fires an error if the default namespace
+       *     couldn't be "undeclared". 
+       */
        ret = xmlSearchNs(out->doc, out, NULL);
-       if (ret != NULL) {
-           ret = xmlNewNs(out, URI, prefix);
+       if ((ret == NULL) ||
+           (ret->href == NULL) || (ret->href[0] == 0))
            return(ret);
+
+       if (ret != NULL) {
+           xmlNsPtr newns;
+
+           newns = xmlNewNs(out, URI, prefix);
+           if (newns == NULL) {
+               xsltTransformError(ctxt, NULL, cur,
+                   "Namespace fixup error: Failed to undeclare "
+                   "the default namespace '%s'.\n",
+                   ret->href);
+           }
+           /*
+           * TODO: Why does this try to return an xmlns="" at all?
+           */
+           return(newns);
        }
        return(NULL);
     }