mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-10 16:20:42 +00:00
Fix error unlinking old namespace
This commit is contained in:
parent
0d010003f9
commit
d5da27bcbc
1 changed files with 46 additions and 27 deletions
|
@ -39,8 +39,8 @@ cleanup_namespaces(xmlNodePtr node, xmlNsPtr ns)
|
|||
if ((node == NULL) || (ns == NULL))
|
||||
return;
|
||||
|
||||
if ((node->type == XML_ATTRIBUTE_NODE) ||
|
||||
(node->type == XML_ELEMENT_NODE))
|
||||
if ((node->type == XML_ATTRIBUTE_NODE)
|
||||
|| (node->type == XML_ELEMENT_NODE))
|
||||
{
|
||||
xmlNsPtr ns1 = node->ns;
|
||||
|
||||
|
@ -50,19 +50,23 @@ cleanup_namespaces(xmlNodePtr node, xmlNsPtr ns)
|
|||
}
|
||||
|
||||
// Either both the same or one NULL and the other the same
|
||||
if (ns1 != NULL &&
|
||||
(((ns1->href == NULL) &&
|
||||
(xmlStrcmp(ns1->prefix, ns->prefix) == 0)) ||
|
||||
/*
|
||||
((ns1->prefix == NULL) &&
|
||||
(xmlStrcmp(ns1->href, ns->href) == 0)) ||
|
||||
*/
|
||||
((xmlStrcmp(ns1->prefix, ns->prefix) == 0) &&
|
||||
(xmlStrcmp(ns1->href, ns->href) == 0))))
|
||||
{
|
||||
//xmlFreeNs(ns1);
|
||||
xmlSetNs(node, ns);
|
||||
}
|
||||
if (ns1 != NULL)
|
||||
{
|
||||
BOOL equalPrefix;
|
||||
|
||||
equalPrefix = (xmlStrcmp(ns1->prefix, ns->prefix) == 0) ? YES : NO;
|
||||
|
||||
if (equalPrefix
|
||||
&& ((ns1->href == NULL)
|
||||
|| (xmlStrcmp(ns1->href, ns->href) == 0)))
|
||||
{
|
||||
xmlSetNs(node, ns);
|
||||
if (ns1->href != NULL)
|
||||
{
|
||||
//xmlFreeNs(ns1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleanup_namespaces(node->children, ns);
|
||||
cleanup_namespaces(node->next, ns);
|
||||
|
@ -73,9 +77,11 @@ cleanup_namespaces(xmlNodePtr node, xmlNsPtr ns)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
BOOL
|
||||
ensure_oldNs(xmlNodePtr node)
|
||||
{
|
||||
BOOL newDoc = NO;
|
||||
|
||||
if (node->doc == NULL)
|
||||
{
|
||||
// Create a private document for this node
|
||||
|
@ -86,6 +92,7 @@ ensure_oldNs(xmlNodePtr node)
|
|||
#else
|
||||
xmlSetTreeDoc(node, tmp);
|
||||
#endif
|
||||
newDoc = YES;
|
||||
}
|
||||
if (node->doc->oldNs == NULL)
|
||||
{
|
||||
|
@ -96,6 +103,7 @@ ensure_oldNs(xmlNodePtr node)
|
|||
ns->prefix = xmlStrdup((const xmlChar *)"xml");
|
||||
node->doc->oldNs = ns;
|
||||
}
|
||||
return newDoc;
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -551,11 +559,15 @@ isEqualTree(xmlNodePtr nodeA, xmlNodePtr nodeB)
|
|||
if (tmp)
|
||||
{
|
||||
// Try to resolve half defined namespaces
|
||||
xmlNsPtr ns = tmp->oldNs;
|
||||
xmlNsPtr ns;
|
||||
xmlNsPtr last = NULL;
|
||||
|
||||
ensure_oldNs(parentNode);
|
||||
if (ensure_oldNs(parentNode))
|
||||
{
|
||||
detached = parentNode->doc;
|
||||
}
|
||||
|
||||
ns = tmp->oldNs;
|
||||
while (ns != NULL)
|
||||
{
|
||||
BOOL resolved = NO;
|
||||
|
@ -594,7 +606,7 @@ isEqualTree(xmlNodePtr nodeA, xmlNodePtr nodeB)
|
|||
// Unlink in old
|
||||
if (last == NULL)
|
||||
{
|
||||
tmp->oldNs = NULL;
|
||||
tmp->oldNs = tmp->oldNs->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1801,9 +1813,9 @@ execute_xpath(xmlNodePtr node, NSString *xpath_exp, NSDictionary *constants,
|
|||
}
|
||||
else
|
||||
{
|
||||
const xmlChar *xmlName = XMLSTRING(name);
|
||||
xmlChar *prefix = NULL;
|
||||
xmlChar *localName;
|
||||
const xmlChar *xmlName = XMLSTRING(name);
|
||||
xmlChar *prefix = NULL;
|
||||
xmlChar *localName;
|
||||
|
||||
if (NULL == xmlName)
|
||||
{
|
||||
|
@ -1814,8 +1826,8 @@ execute_xpath(xmlNodePtr node, NSString *xpath_exp, NSDictionary *constants,
|
|||
localName = xmlSplitQName2(xmlName, &prefix);
|
||||
if (prefix != NULL)
|
||||
{
|
||||
if ((theNode->type == XML_ATTRIBUTE_NODE) ||
|
||||
(theNode->type == XML_ELEMENT_NODE))
|
||||
if ((theNode->type == XML_ATTRIBUTE_NODE)
|
||||
|| (theNode->type == XML_ELEMENT_NODE))
|
||||
{
|
||||
if ((theNode->ns != NULL && theNode->ns->prefix == NULL))
|
||||
{
|
||||
|
@ -1835,7 +1847,10 @@ execute_xpath(xmlNodePtr node, NSString *xpath_exp, NSDictionary *constants,
|
|||
{
|
||||
xmlNsPtr oldNs;
|
||||
|
||||
ensure_oldNs(theNode);
|
||||
if (ensure_oldNs(theNode))
|
||||
{
|
||||
detached = theNode->doc;
|
||||
}
|
||||
|
||||
// Fake the name space and fix it later
|
||||
// This function is private, so re reimplemt it.
|
||||
|
@ -1843,7 +1858,8 @@ execute_xpath(xmlNodePtr node, NSString *xpath_exp, NSDictionary *constants,
|
|||
oldNs = theNode->doc->oldNs;
|
||||
while (oldNs)
|
||||
{
|
||||
if (oldNs->prefix != NULL && xmlStrEqual(oldNs->prefix, prefix))
|
||||
if (oldNs->prefix != NULL
|
||||
&& xmlStrEqual(oldNs->prefix, prefix))
|
||||
{
|
||||
ns = oldNs;
|
||||
break;
|
||||
|
@ -1964,7 +1980,10 @@ execute_xpath(xmlNodePtr node, NSString *xpath_exp, NSDictionary *constants,
|
|||
{
|
||||
xmlNsPtr oldNs;
|
||||
|
||||
ensure_oldNs(theNode);
|
||||
if (ensure_oldNs(theNode))
|
||||
{
|
||||
detached = theNode->doc;
|
||||
}
|
||||
|
||||
// Fake the name space and fix it later
|
||||
// This function is private, so re reimplemt it.
|
||||
|
|
Loading…
Reference in a new issue