Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bug fix for issue #25 - Freshly created Node will crash if sent a des…

…cription message
  • Loading branch information...
commit e2a3734aa96dc197ab3dc5e85439849cba9af5c6 1 parent 430a40d
@robbiehanson authored
View
139 KissXML/DDXMLNode.m
@@ -198,6 +198,25 @@ - (id)initWithPrimitive:(xmlKindPtr)kindPtr owner:(DDXMLNode *)inOwner
return self;
}
+/**
+ * This method shouldn't be used.
+ * To maintain compatibility with Apple, we return an invalid node.
+**/
+- (id)init
+{
+ self = [super init];
+
+ if ([self isKindOfClass:[DDXMLInvalidNode class]])
+ {
+ return self;
+ }
+ else
+ {
+ [self release];
+ return [[DDXMLInvalidNode alloc] init];
+ }
+}
+
- (void)dealloc
{
#if DDXML_DEBUG_MEMORY_ISSUES
@@ -2751,3 +2770,123 @@ - (NSString *)URI
}
@end
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark -
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+@implementation DDXMLInvalidNode
+
+// #pragma mark Properties
+
+- (DDXMLNodeKind)kind {
+ return DDXMLInvalidKind;
+}
+
+- (void)setName:(NSString *)name { }
+- (NSString *)name {
+ return nil;
+}
+
+- (void)setObjectValue:(id)value { }
+- (id)objectValue {
+ return nil;
+}
+
+- (void)setStringValue:(NSString *)string { }
+- (void)setStringValue:(NSString *)string resolvingEntities:(BOOL)resolve { }
+- (NSString *)stringValue {
+ return nil;
+}
+
+// #pragma mark Tree Navigation
+
+- (NSUInteger)index {
+ return 0;
+}
+
+- (NSUInteger)level {
+ return 0;
+}
+
+- (DDXMLDocument *)rootDocument {
+ return nil;
+}
+
+- (DDXMLNode *)parent {
+ return nil;
+}
+- (NSUInteger)childCount {
+ return 0;
+}
+- (NSArray *)children {
+ return [NSArray array];
+}
+- (DDXMLNode *)childAtIndex:(NSUInteger)index {
+ return nil;
+}
+
+- (DDXMLNode *)previousSibling {
+ return nil;
+}
+- (DDXMLNode *)nextSibling {
+ return nil;
+}
+
+- (DDXMLNode *)previousNode {
+ return nil;
+}
+- (DDXMLNode *)nextNode {
+ return nil;
+}
+
+- (void)detach { }
+
+- (NSString *)XPath {
+ return @"";
+}
+
+// #pragma mark QNames
+
+- (NSString *)localName {
+ return nil;
+}
+- (NSString *)prefix {
+ return @"";
+}
+
+- (void)setURI:(NSString *)URI { }
+- (NSString *)URI {
+ return nil;
+}
+
+// #pragma mark Output
+
+- (NSString *)description {
+ return @"";
+}
+- (NSString *)XMLString {
+ return @"";
+}
+- (NSString *)XMLStringWithOptions:(NSUInteger)options {
+ return @"";
+}
+- (NSString *)canonicalXMLStringPreservingComments:(BOOL)comments {
+ return nil;
+}
+
+// #pragma mark XPath/XQuery
+
+- (NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error {
+ return [NSArray array];
+}
+
+- (NSArray *)objectsForXQuery:(NSString *)xquery constants:(NSDictionary *)constants error:(NSError **)error {
+ return [NSArray array];
+}
+- (NSArray *)objectsForXQuery:(NSString *)xquery error:(NSError **)error {
+ return [NSArray array];
+}
+
+@end
+
View
12 KissXML/Private/DDXMLPrivate.h
@@ -157,6 +157,18 @@ NS_INLINE BOOL IsXmlNsPtr(void *kindPtr)
#pragma mark -
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+@interface DDXMLInvalidNode : DDXMLNode
+{
+}
+
+// Overrides several methods in DDXMLNode
+
+@end
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark -
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
@interface DDXMLNode (PrivateAPI)
+ (id)nodeWithUnknownPrimitive:(xmlKindPtr)kindPtr owner:(DDXMLNode *)owner;
View
28 UnitTesting/DDXMLTesting.m
@@ -46,6 +46,7 @@ + (void)testAttrWithColonInName;
+ (void)testMemoryIssueDebugging;
+ (void)testAttrNs;
+ (void)testNsDetatchCopy;
++ (void)testInvalidNode;
@end
#pragma mark -
@@ -92,6 +93,7 @@ + (void)performTests
[self testMemoryIssueDebugging];
[self testAttrNs];
[self testNsDetatchCopy];
+ [self testInvalidNode];
[self tearDown];
@@ -2130,6 +2132,32 @@ + (void)testNsDetatchCopy
[pool drain];
}
++ (void)testInvalidNode
+{
+ NSLog(@"Starting %@...", NSStringFromSelector(_cmd));
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSXMLNode *nsNode = [[NSXMLNode alloc] init];
+ DDXMLNode *ddNode = [[DDXMLNode alloc] init];
+
+ NSAssert([NSStringFromClass([ddNode class]) isEqualToString:@"DDXMLInvalidNode"], @"Failed test 0");
+
+ NSAssert([nsNode kind] == NSXMLInvalidKind, @"Failed CHECK 1a");
+ NSAssert([ddNode kind] == DDXMLInvalidKind, @"Failed test 1a");
+
+ NSString *nsName = [nsNode name];
+ NSString *ddName = [ddNode name];
+
+ NSAssert(nsName == nil && ddName == nil, @"Failed test 2 - ns(%@) dd(%@)", nsName, ddName);
+
+ NSString *nsDesc = [nsNode description];
+ NSString *ddDesc = [ddNode description];
+
+ NSAssert(nsDesc && [nsDesc isEqualToString:ddDesc], @"Failed test 3 - ns(%@) dd(%@)", nsDesc, ddDesc);
+
+ [pool drain];
+}
+
@end
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Please sign in to comment.
Something went wrong with that request. Please try again.