Whole file

martinblech/xmltodict

The author described this change as fix(unparse): handle non-string `#text` with attributes; unify value conversion. It counts as a record because the check below fails on the code as it stood at ab4c86fed and passes on 927a025ae, with nothing else changed between the two runs.

Fix saved2025-09-12
Sharing licenceMIT · LICENSE
Change size+14 4

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

fix(unparse): handle non-string `#text` with attributes; unify value conversion

The change

374374 return handler.item
375375
376376
377+def _convert_value_to_string(value):
378+ """Convert a value to its string representation for XML output.
379+
380+ Handles boolean values consistently by converting them to lowercase.
381+ """
382+ if isinstance(value, (str, bytes)):
383+ return value
384+ if isinstance(value, bool):
385+ return "true" if value else "false"
386+ return str(value)
387+
388+
377389 def _has_angle_brackets(value):
378390 """Return True if value (a str) contains '<' or '>'.
379391
463475 raise ValueError('document with multiple roots')
464476 if v is None:
465477 v = _dict()
466- elif isinstance(v, bool):
467- v = 'true' if v else 'false'
468478 elif not isinstance(v, (dict, str)):
469479 if expand_iter and hasattr(v, '__iter__'):
470480 v = _dict(((expand_iter, v),))
471481 else:
472- v = str(v)
482+ v = _convert_value_to_string(v)
473483 if isinstance(v, str):
474484 v = _dict(((cdata_key, v),))
475485 cdata = None
477487 children = []
478488 for ik, iv in v.items():
479489 if ik == cdata_key:
480- cdata = iv
490+ cdata = _convert_value_to_string(iv)
481491 continue
482492 if isinstance(ik, str) and ik.startswith(attr_prefix):
483493 ik = _process_namespace(ik, namespaces, namespace_separator,

The check that tells the two apart

failpass·tests/test_dicttoxml.py::DictToXMLTestCase::test_non_string_text_with_attributes

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 itab4c86fed24dc8ef0e932a524edfb01c6453ecf6
Broken version dated2025-09-12
Modulexmltodict
Units changed_emit
Fingerprint7f4a10241a28ca3a
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