Permalink
Browse files

Possbile fix for Issue #21 (calling initWithXMLString: options: error:

with nil)
  • Loading branch information...
1 parent 540e643 commit 9968b3c4738d5737f44ec1a25e715707b3670363 @5minpause 5minpause committed Apr 4, 2012
View
8 Source/CXMLDocument.m
@@ -72,11 +72,11 @@ - (id)initWithXMLString:(NSString *)inString options:(NSUInteger)inOptions error
{
xmlErrorPtr theLastErrorPtr = xmlGetLastError();
- NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSString stringWithUTF8String:theLastErrorPtr->message], NSLocalizedDescriptionKey,
- NULL];
-
+ NSString* message = [NSString stringWithUTF8String:
+ (theLastErrorPtr ? theLastErrorPtr->message : "Unknown error")];
+ NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
+ message, NSLocalizedDescriptionKey, NULL];
theError = [NSError errorWithDomain:@"CXMLErrorDomain" code:1 userInfo:theUserInfo];
xmlResetLastError();
View
8 Support/UnitTests/Source/BasicTests.m
@@ -75,6 +75,14 @@ - (void)test_badXMLTest
STAssertNotNil(theError, NULL);
}
+- (void)test_nilXMLTest
+{
+ NSError *theError = NULL;
+ CXMLDocument *theXMLDocument = [[[CXMLDocument alloc] initWithXMLString:nil options:0 error:&theError] autorelease];
+ STAssertNil(theXMLDocument, NULL);
+ STAssertNotNil(theError, NULL);
+}
+
- (void)test_badXMLTestFromData
{
NSError *theError = NULL;
View
BIN .../project.xcworkspace/xcuserdata/holgerfrohloff.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
View
29 TouchXML.xcodeproj/xcuserdata/holgerfrohloff.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>SuppressBuildableAutocreation</key>
+ <dict>
+ <key>451E6E301152EB4A0024ABA5</key>
+ <dict>
+ <key>primary</key>
+ <true/>
+ </dict>
+ <key>456A848A0D81DB06000E29C9</key>
+ <dict>
+ <key>primary</key>
+ <true/>
+ </dict>
+ <key>457940FE0D82217800EB2D22</key>
+ <dict>
+ <key>primary</key>
+ <true/>
+ </dict>
+ <key>457941040D82219400EB2D22</key>
+ <dict>
+ <key>primary</key>
+ <true/>
+ </dict>
+ </dict>
+</dict>
+</plist>

0 comments on commit 9968b3c

Please sign in to comment.