diff --git a/api/funkwhale_api/subsonic/renderers.py b/api/funkwhale_api/subsonic/renderers.py index e9703d48d..51efb4206 100644 --- a/api/funkwhale_api/subsonic/renderers.py +++ b/api/funkwhale_api/subsonic/renderers.py @@ -6,6 +6,10 @@ from rest_framework import renderers import funkwhale_api +class TagValue(str): + """Use this for string values that must be rendered as tags instead of attributes in XML.""" + + # from https://stackoverflow.com/a/8915039 # because I want to avoid a lxml dependency just for outputting cdata properly # in a RSS feed @@ -83,6 +87,10 @@ def dict_to_xml_tree(root_tag, d, parent=None): el = ET.Element(key) el.text = str(obj) root.append(el) + elif isinstance(value, TagValue): + el = ET.Element(key) + el.text = str(value) + root.append(el) else: if key == "value": root.text = str(value) diff --git a/api/tests/subsonic/test_renderers.py b/api/tests/subsonic/test_renderers.py index 1b49753e4..c404555da 100644 --- a/api/tests/subsonic/test_renderers.py +++ b/api/tests/subsonic/test_renderers.py @@ -79,9 +79,10 @@ def test_xml_renderer_dict_to_xml(): "hello": "world", "item": [{"this": 1, "value": "text"}, {"some": "node"}], "list": [1, 2], + "some-tag": renderers.TagValue("foo"), } expected = """ -text12""" +text12foo""" # noqa result = renderers.dict_to_xml_tree("key", payload) exp = ET.fromstring(expected) assert ET.tostring(result) == ET.tostring(exp)