Skip to content

Commit

Permalink
Possbile fix for Issue #21 (calling initWithXMLString: options: error:
Browse files Browse the repository at this point in the history
with nil)
  • Loading branch information
5minpause committed Apr 4, 2012
1 parent 540e643 commit 9968b3c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Source/CXMLDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions Support/UnitTests/Source/BasicTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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.