Whole file

martinblech/xmltodict

The author described this change as fix #12: postprocess cdata items too. It counts as a record because the check below fails on the code as it stood at 39c6f9604 and passes on b4ce7e7e6, with nothing else changed between the two runs.

Fix saved2013-01-11
Sharing licenceMIT · LICENSE
Change size+11 10

What the code was meant to do, written into the code itself as a save note

fix #12: postprocess cdata items too

The change

8484 item = self.dict_constructor()
8585 if item is not None:
8686 if data:
87- item[self.cdata_key] = data
88- self.push_data(name, item)
87+ self.push_data(item, self.cdata_key, data)
88+ self.item = self.push_data(self.item, name, item)
8989 else:
90- self.push_data(name, data)
90+ self.item = self.push_data(self.item, name, data)
9191 else:
9292 self.item = self.data = None
9393 self.path.pop()
9898 else:
9999 self.data += self.cdata_separator + data
100100
101- def push_data(self, key, data):
101+ def push_data(self, item, key, data):
102102 if self.postprocessor is not None:
103103 result = self.postprocessor(self.path, key, data)
104104 if result is None:
105- return
105+ return item
106106 key, data = result
107- if self.item is None:
108- self.item = self.dict_constructor()
107+ if item is None:
108+ item = self.dict_constructor()
109109 try:
110- value = self.item[key]
110+ value = item[key]
111111 if isinstance(value, list):
112112 value.append(data)
113113 else:
114- self.item[key] = [value, data]
114+ item[key] = [value, data]
115115 except KeyError:
116- self.item[key] = data
116+ item[key] = data
117+ return item
117118
118119 def parse(xml_input, *args, **kwargs):
119120 """Parse the given XML input and convert it into a dictionary.

The check that tells the two apart

failpass·tests/test_xmltodict.py::XMLToDictTestCase::test_postprocess_whitespace

Check file tests/test_xmltodict.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it39c6f9604f12b9e3321153fca6fd8d47a45899c8
Broken version dated2013-01-08
Modulexmltodict
Units changed_DictSAXHandler
Fingerprint5257606666bbe47f
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in martinblech/xmltodict