From 904a482698b08a3e44c076b493fe311feee0b87a Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Fri, 19 Jul 2019 07:53:37 +0200 Subject: [PATCH] Ensure we render tag text properly in Subsonic XML --- api/funkwhale_api/subsonic/renderers.py | 5 ++++- api/tests/subsonic/test_renderers.py | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/api/funkwhale_api/subsonic/renderers.py b/api/funkwhale_api/subsonic/renderers.py index e4b647051..527b3fa1e 100644 --- a/api/funkwhale_api/subsonic/renderers.py +++ b/api/funkwhale_api/subsonic/renderers.py @@ -53,5 +53,8 @@ def dict_to_xml_tree(root_tag, d, parent=None): for obj in value: root.append(dict_to_xml_tree(key, obj, parent=root)) else: - root.set(key, str(value)) + if key == "value": + root.text = str(value) + else: + root.set(key, str(value)) return root diff --git a/api/tests/subsonic/test_renderers.py b/api/tests/subsonic/test_renderers.py index acd5500e6..501ae48ce 100644 --- a/api/tests/subsonic/test_renderers.py +++ b/api/tests/subsonic/test_renderers.py @@ -67,9 +67,12 @@ def test_json_renderer(): def test_xml_renderer_dict_to_xml(): - payload = {"hello": "world", "item": [{"this": 1}, {"some": "node"}]} + payload = { + "hello": "world", + "item": [{"this": 1, "value": "text"}, {"some": "node"}], + } expected = """ -""" +text""" result = renderers.dict_to_xml_tree("key", payload) exp = ET.fromstring(expected) assert ET.tostring(result) == ET.tostring(exp)