Skip to content

Commit

Permalink
Merge pull request #505 from spenrose/xml-attributes-bug
Browse files Browse the repository at this point in the history
This fixes a bug where attributes of a object would also get added to parent object.
  • Loading branch information
Jeff Arena committed Jan 20, 2012
2 parents d0b8594 + c6fd924 commit fa44916
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Code/Support/Parsers/XML/RKXMLParserLibXML.m
Expand Up @@ -37,6 +37,8 @@ - (id)parseNode:(xmlNode*)node {
// Assume that empty strings are irrelevant and go for an attribute-collection instead
if ([val length] == 0) {
val = [NSMutableDictionary dictionary];
attrs = [NSMutableDictionary dictionary];
oldVal = [attrs valueForKey:nodeName];
NSMutableDictionary* elem = [NSMutableDictionary dictionaryWithObject:val forKey:nodeName];
[nodes addObject:elem];
} else {
Expand All @@ -50,7 +52,7 @@ - (id)parseNode:(xmlNode*)node {
}

// Only add attributes to nodes if there actually is one.
if (![nodes containsObject:attrs]) {
if (![nodes containsObject:attrs] && [attrs count] > 0) {
[nodes addObject:attrs];
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion Specs/Support/RKXMLParserSpec.m
Expand Up @@ -110,7 +110,8 @@ - (void)testShouldParseXMLWithAttributesInTextNodes {
NSDictionary* exchangeRate = [result objectForKey:@"exchange_rate"];
assertThat(exchangeRate, is(notNilValue()));
assertThat([exchangeRate objectForKey:@"type"], is(equalTo(@"XML_RATE_TYPE_EBNK_MIDDLE")));
assertThat([exchangeRate objectForKey:@"valid_from"], is(equalTo(@"2011-08-03 00:00:00.0")));
assertThat([exchangeRate objectForKey:@"valid_from"], is(equalTo(@"2011-08-03 00:00:00.0")));
assertThat([exchangeRate objectForKey:@"name"], nilValue()); // This is to test for bug in parsing
NSArray* currency = [exchangeRate objectForKey:@"currency"];
assertThat(currency, hasCountOf(3));
NSDictionary* firstCurrency = [currency objectAtIndex:0];
Expand Down

0 comments on commit fa44916

Please sign in to comment.