django-rest-framework-xml
django-rest-framework-xml copied to clipboard
Error when a key is a number
The job of django-rest-framework-xml is to convert dictionaries to xml. It is valid for a python dictionary to contain a key which is either an integer or the string representation of an integer. And it renders find to json. But the xml renderer fails: (i) if the key is an integer, sax will raise an exception; (2) if it's a string rep of an integer, it will render to invalid xml because an xml tag name cannot be a number.
I propose we slightly modify the renderer's _to_xml method to add this code when iterating each key:
attributes = {}
if isinstance(key, six.integer_types):
attributes = {'number': force_text(key)}
key = 'element'
Does that seem reasonable?