* Source/NSXMLNode.m (-copyWithZone_): Use value 1 instead of 2

for deep copy. Bug found by Doug Simons <doug.simons@testplant.com>.
* Source/NSXMLNode.m (-rootDocument): Don't return the private
document.
* Source/NSXMLNode.m (-nextSibling, -previousSibling): Protect
against namspace nodes.
* Tests/base/NSXMLNode/transfer.m: New test case for problem
reported by Doug Simons.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34988 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2012-03-23 09:48:24 +00:00
parent 887362645d
commit 511ebc6580
3 changed files with 72 additions and 4 deletions

View file

@ -1,3 +1,13 @@
2012-03-23 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSXMLNode.m (-copyWithZone_): Use value 1 instead of 2
for deep copy. Bug found by Doug Simons <doug.simons@testplant.com>.
* Source/NSXMLNode.m (-rootDocument): Don't return the private document.
* Source/NSXMLNode.m (-nextSibling, -previousSibling): Protect
against namspace nodes.
* Tests/base/NSXMLNode/transfer.m: New test case for problem
reported by Doug Simons.
2012-03-22 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSXMLElement.m,

View file

@ -1147,7 +1147,7 @@ execute_xpath(NSXMLNode *xmlNode, NSString *xpath_exp, NSString *nmspaces)
- (id) copyWithZone: (NSZone*)zone
{
NSXMLNode *c = [[self class] allocWithZone: zone];
xmlNodePtr newNode = xmlCopyNode([self _node], 2); // make a deep copy
xmlNodePtr newNode = xmlCopyNode([self _node], 1); // make a deep copy
clearPrivatePointers(newNode);
c = [c _initWithNode: newNode kind: internal->kind];
@ -1591,7 +1591,17 @@ execute_xpath(NSXMLNode *xmlNode, NSString *xpath_exp, NSString *nmspaces)
- (NSXMLNode*) nextSibling
{
return [NSXMLNode _objectForNode: internal->node->next];
xmlNodePtr node = internal->node;
if (NULL == node)
{
return nil;
}
if (XML_NAMESPACE_DECL == node->type)
{
return nil;
}
return [NSXMLNode _objectForNode: node->next];
}
- (id) objectValue
@ -1648,13 +1658,40 @@ execute_xpath(NSXMLNode *xmlNode, NSString *xpath_exp, NSString *nmspaces)
- (NSXMLNode*) previousSibling
{
return [NSXMLNode _objectForNode: internal->node->prev];
xmlNodePtr node = internal->node;
if (NULL == node)
{
return nil;
}
if (XML_NAMESPACE_DECL == node->type)
{
return nil;
}
return [NSXMLNode _objectForNode: node->prev];
}
- (NSXMLDocument*) rootDocument
{
xmlNodePtr node = internal->node;
if (NULL == node)
{
return nil;
}
if (XML_NAMESPACE_DECL == node->type)
{
return nil;
}
if (NULL == node->parent)
{
// This is a standalone node, we still may have a private document,
// but we don't want to return this.
return nil;
}
return
(NSXMLDocument *)[NSXMLNode _objectForNode: (xmlNodePtr)(internal->node->doc)];
(NSXMLDocument *)[NSXMLNode _objectForNode: (xmlNodePtr)(node->doc)];
}
- (NSString*) stringValue

View file

@ -0,0 +1,21 @@
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSXMLDocument.h>
#import <Foundation/NSXMLElement.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSXMLElement *elem1 = [[NSXMLElement alloc] initWithXMLString: @"<num>6</num>" error: NULL];
NSXMLElement *elem2 = [[NSXMLElement alloc] initWithXMLString: @"<num>7</num>" error: NULL];
NSXMLElement *copy1 = [elem1 copy];
NSXMLElement *copy2 = [elem2 copy];
[copy1 setStringValue: @"7"];
PASS_EQUAL(copy1, copy2, "equal after setStringValue:");
[arp drain];
arp = nil;
return 0;
}