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.
Projectmartinblech/xmltodict
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
| 84 | 84 | item = self.dict_constructor() | |
| 85 | 85 | if item is not None: | |
| 86 | 86 | 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) | |
| 89 | 89 | else: | |
| 90 | - | self.push_data(name, data) | |
| 90 | + | self.item = self.push_data(self.item, name, data) | |
| 91 | 91 | else: | |
| 92 | 92 | self.item = self.data = None | |
| 93 | 93 | self.path.pop() | |
| ⋯ | |||
| 98 | 98 | else: | |
| 99 | 99 | self.data += self.cdata_separator + data | |
| 100 | 100 | ||
| 101 | - | def push_data(self, key, data): | |
| 101 | + | def push_data(self, item, key, data): | |
| 102 | 102 | if self.postprocessor is not None: | |
| 103 | 103 | result = self.postprocessor(self.path, key, data) | |
| 104 | 104 | if result is None: | |
| 105 | - | return | |
| 105 | + | return item | |
| 106 | 106 | 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() | |
| 109 | 109 | try: | |
| 110 | - | value = self.item[key] | |
| 110 | + | value = item[key] | |
| 111 | 111 | if isinstance(value, list): | |
| 112 | 112 | value.append(data) | |
| 113 | 113 | else: | |
| 114 | - | self.item[key] = [value, data] | |
| 114 | + | item[key] = [value, data] | |
| 115 | 115 | except KeyError: | |
| 116 | - | self.item[key] = data | |
| 116 | + | item[key] = data | |
| 117 | + | return item | |
| 117 | 118 | ||
| 118 | 119 | def parse(xml_input, *args, **kwargs): | |
| 119 | 120 | """Parse the given XML input and convert it into a dictionary. | |
The check that tells the two apart
fail→pass·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
- 2026-02-15fix(unparse): serialize None text/attrs as empty values (fixes #401)
- 2025-09-17fix: allow DOCTYPE with disable_entities=True (default)
- 2025-09-16fix: fail closed when entities disabled
- 2025-09-16fix: validate XML comments
- 2025-09-12fix(unparse): handle non-string `#text` with attributes; unify value conversion
- 2025-09-12fix(unparse): skip empty lists to keep pretty/compact outputs consistent