From 1b969d0fc923d564baea58a6759600c6707bdd8a Mon Sep 17 00:00:00 2001 From: "Kasimier T. Buchcik" Date: Mon, 15 May 2006 20:35:12 +0000 Subject: [PATCH] Fixed bug #302020, reported by Thomas Blatter. * libxslt/namespaces.c libxslt/attributes.c: Fixed bug #302020, reported by Thomas Blatter. --- ChangeLog | 5 +++++ libxslt/attributes.c | 7 +++++-- libxslt/namespaces.c | 28 ++++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index ea37ba9..6f13041 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon May 15 22:32:13 CEST 2006 Kasimier Buchcik + + * libxslt/namespaces.c libxslt/attributes.c: + Fixed bug #302020, reported by Thomas Blatter. + Fri May 12 23:23:06 CEST 2006 Kasimier Buchcik * libxslt/documents.c libxslt/namespaces.c diff --git a/libxslt/attributes.c b/libxslt/attributes.c index 849b2f6..d72f41d 100644 --- a/libxslt/attributes.c +++ b/libxslt/attributes.c @@ -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, diff --git a/libxslt/namespaces.c b/libxslt/namespaces.c index b9bedc2..8f783bb 100644 --- a/libxslt/namespaces.c +++ b/libxslt/namespaces.c @@ -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); } -- 2.7.4