Whole file
martinblech/xmltodict
The author described this change as “fix(unparse): skip empty lists to keep pretty/compact outputs consistent”. It counts as a record because the check below fails on the code as it stood at 220240c5e and passes on ab4c86fed, with nothing else changed between the two runs.
Projectmartinblech/xmltodict
Fix saved2025-09-12
Sharing licenceMIT · LICENSE
Change size+2 −0
What the code was meant to do, written into the code itself as a save note
fix(unparse): skip empty lists to keep pretty/compact outputs consistent
The change
| 494 | 494 | _validate_name(attr_name, "attribute") | |
| 495 | 495 | attrs[attr_name] = iv | |
| 496 | 496 | continue | |
| 497 | + | if isinstance(iv, list) and not iv: | |
| 498 | + | continue # Skip empty lists to avoid creating empty child elements | |
| 497 | 499 | children.append((ik, iv)) | |
| 498 | 500 | if isinstance(indent, int): | |
| 499 | 501 | indent = ' ' * indent |
The check that tells the two apart
fail→pass·tests/test_dicttoxml.py::DictToXMLTestCase::test_pretty_print_and_short_empty_elements_consistency
Check file tests/test_dicttoxml.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 it220240c5eb2d12b75adf26cc84ec9c803ce8bb2b
Broken version dated2025-09-12
Modulexmltodict
Units changed_emit
Fingerprintb2bba672d32d1304
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(streaming): avoid parent accumulation at item_depth; add regression tests