Skip to content
This repository

This fixes a bug where attributes of a object would also get added to parent object. #505

Merged
merged 1 commit into from over 2 years ago

2 participants

Scott Penrose Jeff Arena
Scott Penrose

XML to parse

<exchange_rate type="XML_RATE_TYPE_EBNK_MIDDLE" valid_from="2011-08-03 00:00:00.0">
    <currency name="AUD" quota="1" rate="18.416"/>
    <currency name="HRK" quota="1" rate="3.25017"/>
    <currency name="DKK" quota="1" rate="3.251"/>
</exchange_rate>

BEFORE FIX

<CFBasicHash 0xab93140 [0x520b38]>{type = mutable dict, count = 1,
entries =>
    0 : <CFString 0xabacac0 [0x520b38]>{contents = "exchange_rate"} = <CFBasicHash 0xaba99e0 [0x520b38]>{type = mutable dict, count = 6,
entries =>
    0 : <CFString 0xabc1e40 [0x520b38]>{contents = "currency"} = (
        {
        name = AUD;
        quota = 1;
        rate = "18.416";
    },
        {
        name = HRK;
        quota = 1;
        rate = "3.25017";
    },
        {
        name = DKK;
        quota = 1;
        rate = "3.251";
    }
)
    1 : <CFString 0xaba9940 [0x520b38]>{contents = "name"} = <CFString 0xaba9960 [0x520b38]>{contents = "DKK"}
    2 : <CFString 0xaba9990 [0x520b38]>{contents = "rate"} = <CFString 0xaba99c0 [0x520b38]>{contents = "3.251"}
    3 : <CFString 0xaba9980 [0x520b38]>{contents = "quota"} = <CFString 0xaba99a0 [0x520b38]>{contents = "1"}
    4 : <CFString 0xab93180 [0x520b38]>{contents = "type"} = <CFString 0xab931b0 [0x520b38]>{contents = "XML_RATE_TYPE_EBNK_MIDDLE"}
    5 : <CFString 0xab93190 [0x520b38]>{contents = "valid_from"} = <CFString 0xab93220 [0x520b38]>{contents = "2011-08-03 00:00:00.0"}
}

}

AFTER FIX

<CFBasicHash 0xa689830 [0x520b38]>{type = mutable dict, count = 1,
entries =>
    0 : <CFString 0xa6816a0 [0x520b38]>{contents = "exchange_rate"} = <CFBasicHash 0xa6897c0 [0x520b38]>{type = mutable dict, count = 3,
entries =>
    0 : <CFString 0xa692100 [0x520b38]>{contents = "valid_from"} = <CFString 0xa692190 [0x520b38]>{contents = "2011-08-03 00:00:00.0"}
    1 : <CFString 0xa680860 [0x520b38]>{contents = "currency"} = (
        {
        name = AUD;
        quota = 1;
        rate = "18.416";
    },
        {
        name = HRK;
        quota = 1;
        rate = "3.25017";
    },
        {
        name = DKK;
        quota = 1;
        rate = "3.251";
    }
)
    2 : <CFString 0xa6920f0 [0x520b38]>{contents = "type"} = <CFString 0xa692120 [0x520b38]>{contents = "XML_RATE_TYPE_EBNK_MIDDLE"}
}

}
Scott Penrose spenrose This fixes a bug where attributes of a object would also get added to…
… parent object.

XML to parse
```
<exchange_rate type="XML_RATE_TYPE_EBNK_MIDDLE" valid_from="2011-08-03 00:00:00.0">
    <currency name="AUD" quota="1" rate="18.416"/>
    <currency name="HRK" quota="1" rate="3.25017"/>
    <currency name="DKK" quota="1" rate="3.251"/>
</exchange_rate>
```

BEFORE FIX
```
<CFBasicHash 0xab93140 [0x520b38]>{type = mutable dict, count = 1,
entries =>
	0 : <CFString 0xabacac0 [0x520b38]>{contents = "exchange_rate"} = <CFBasicHash 0xaba99e0 [0x520b38]>{type = mutable dict, count = 6,
entries =>
	0 : <CFString 0xabc1e40 [0x520b38]>{contents = "currency"} = (
        {
        name = AUD;
        quota = 1;
        rate = "18.416";
    },
        {
        name = HRK;
        quota = 1;
        rate = "3.25017";
    },
        {
        name = DKK;
        quota = 1;
        rate = "3.251";
    }
)
	1 : <CFString 0xaba9940 [0x520b38]>{contents = "name"} = <CFString 0xaba9960 [0x520b38]>{contents = "DKK"}
	2 : <CFString 0xaba9990 [0x520b38]>{contents = "rate"} = <CFString 0xaba99c0 [0x520b38]>{contents = "3.251"}
	3 : <CFString 0xaba9980 [0x520b38]>{contents = "quota"} = <CFString 0xaba99a0 [0x520b38]>{contents = "1"}
	4 : <CFString 0xab93180 [0x520b38]>{contents = "type"} = <CFString 0xab931b0 [0x520b38]>{contents = "XML_RATE_TYPE_EBNK_MIDDLE"}
	5 : <CFString 0xab93190 [0x520b38]>{contents = "valid_from"} = <CFString 0xab93220 [0x520b38]>{contents = "2011-08-03 00:00:00.0"}
}

}
```

AFTER FIX
```
<CFBasicHash 0xa689830 [0x520b38]>{type = mutable dict, count = 1,
entries =>
	0 : <CFString 0xa6816a0 [0x520b38]>{contents = "exchange_rate"} = <CFBasicHash 0xa6897c0 [0x520b38]>{type = mutable dict, count = 3,
entries =>
	0 : <CFString 0xa692100 [0x520b38]>{contents = "valid_from"} = <CFString 0xa692190 [0x520b38]>{contents = "2011-08-03 00:00:00.0"}
	1 : <CFString 0xa680860 [0x520b38]>{contents = "currency"} = (
        {
        name = AUD;
        quota = 1;
        rate = "18.416";
    },
        {
        name = HRK;
        quota = 1;
        rate = "3.25017";
    },
        {
        name = DKK;
        quota = 1;
        rate = "3.251";
    }
)
	2 : <CFString 0xa6920f0 [0x520b38]>{contents = "type"} = <CFString 0xa692120 [0x520b38]>{contents = "XML_RATE_TYPE_EBNK_MIDDLE"}
}

}
```
c6fd924
Jeff Arena jeffarena merged commit fa44916 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 14, 2012
Scott Penrose spenrose This fixes a bug where attributes of a object would also get added to…
… parent object.

XML to parse
```
<exchange_rate type="XML_RATE_TYPE_EBNK_MIDDLE" valid_from="2011-08-03 00:00:00.0">
    <currency name="AUD" quota="1" rate="18.416"/>
    <currency name="HRK" quota="1" rate="3.25017"/>
    <currency name="DKK" quota="1" rate="3.251"/>
</exchange_rate>
```

BEFORE FIX
```
<CFBasicHash 0xab93140 [0x520b38]>{type = mutable dict, count = 1,
entries =>
	0 : <CFString 0xabacac0 [0x520b38]>{contents = "exchange_rate"} = <CFBasicHash 0xaba99e0 [0x520b38]>{type = mutable dict, count = 6,
entries =>
	0 : <CFString 0xabc1e40 [0x520b38]>{contents = "currency"} = (
        {
        name = AUD;
        quota = 1;
        rate = "18.416";
    },
        {
        name = HRK;
        quota = 1;
        rate = "3.25017";
    },
        {
        name = DKK;
        quota = 1;
        rate = "3.251";
    }
)
	1 : <CFString 0xaba9940 [0x520b38]>{contents = "name"} = <CFString 0xaba9960 [0x520b38]>{contents = "DKK"}
	2 : <CFString 0xaba9990 [0x520b38]>{contents = "rate"} = <CFString 0xaba99c0 [0x520b38]>{contents = "3.251"}
	3 : <CFString 0xaba9980 [0x520b38]>{contents = "quota"} = <CFString 0xaba99a0 [0x520b38]>{contents = "1"}
	4 : <CFString 0xab93180 [0x520b38]>{contents = "type"} = <CFString 0xab931b0 [0x520b38]>{contents = "XML_RATE_TYPE_EBNK_MIDDLE"}
	5 : <CFString 0xab93190 [0x520b38]>{contents = "valid_from"} = <CFString 0xab93220 [0x520b38]>{contents = "2011-08-03 00:00:00.0"}
}

}
```

AFTER FIX
```
<CFBasicHash 0xa689830 [0x520b38]>{type = mutable dict, count = 1,
entries =>
	0 : <CFString 0xa6816a0 [0x520b38]>{contents = "exchange_rate"} = <CFBasicHash 0xa6897c0 [0x520b38]>{type = mutable dict, count = 3,
entries =>
	0 : <CFString 0xa692100 [0x520b38]>{contents = "valid_from"} = <CFString 0xa692190 [0x520b38]>{contents = "2011-08-03 00:00:00.0"}
	1 : <CFString 0xa680860 [0x520b38]>{contents = "currency"} = (
        {
        name = AUD;
        quota = 1;
        rate = "18.416";
    },
        {
        name = HRK;
        quota = 1;
        rate = "3.25017";
    },
        {
        name = DKK;
        quota = 1;
        rate = "3.251";
    }
)
	2 : <CFString 0xa6920f0 [0x520b38]>{contents = "type"} = <CFString 0xa692120 [0x520b38]>{contents = "XML_RATE_TYPE_EBNK_MIDDLE"}
}

}
```
c6fd924
This page is out of date. Refresh to see the latest.
4 Code/Support/Parsers/XML/RKXMLParserLibXML.m
@@ -37,6 +37,8 @@ - (id)parseNode:(xmlNode*)node {
37 37 // Assume that empty strings are irrelevant and go for an attribute-collection instead
38 38 if ([val length] == 0) {
39 39 val = [NSMutableDictionary dictionary];
  40 + attrs = [NSMutableDictionary dictionary];
  41 + oldVal = [attrs valueForKey:nodeName];
40 42 NSMutableDictionary* elem = [NSMutableDictionary dictionaryWithObject:val forKey:nodeName];
41 43 [nodes addObject:elem];
42 44 } else {
@@ -50,7 +52,7 @@ - (id)parseNode:(xmlNode*)node {
50 52 }
51 53
52 54 // Only add attributes to nodes if there actually is one.
53   - if (![nodes containsObject:attrs]) {
  55 + if (![nodes containsObject:attrs] && [attrs count] > 0) {
54 56 [nodes addObject:attrs];
55 57 }
56 58 } else {
3  Specs/Support/RKXMLParserSpec.m
@@ -110,7 +110,8 @@ - (void)testShouldParseXMLWithAttributesInTextNodes {
110 110 NSDictionary* exchangeRate = [result objectForKey:@"exchange_rate"];
111 111 assertThat(exchangeRate, is(notNilValue()));
112 112 assertThat([exchangeRate objectForKey:@"type"], is(equalTo(@"XML_RATE_TYPE_EBNK_MIDDLE")));
113   - assertThat([exchangeRate objectForKey:@"valid_from"], is(equalTo(@"2011-08-03 00:00:00.0")));
  113 + assertThat([exchangeRate objectForKey:@"valid_from"], is(equalTo(@"2011-08-03 00:00:00.0")));
  114 + assertThat([exchangeRate objectForKey:@"name"], nilValue()); // This is to test for bug in parsing
114 115 NSArray* currency = [exchangeRate objectForKey:@"currency"];
115 116 assertThat(currency, hasCountOf(3));
116 117 NSDictionary* firstCurrency = [currency objectAtIndex:0];

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.