Skip to content
Snippets Groups Projects
Verified Commit 099d82c9 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Fixed a CDATA issue with RSS feeds

parent febe72c3
No related tags found
No related merge requests found
......@@ -5,6 +5,29 @@ from rest_framework import renderers
import funkwhale_api
# from https://stackoverflow.com/a/8915039
# because I want to avoid a lxml dependency just for outputting cdata properly
# in a RSS feed
def CDATA(text=None):
element = ET.Element("![CDATA[")
element.text = text
return element
ET._original_serialize_xml = ET._serialize_xml
def _serialize_xml(write, elem, qnames, namespaces, **kwargs):
if elem.tag == "![CDATA[":
write("<%s%s]]>" % (elem.tag, elem.text))
return
return ET._original_serialize_xml(write, elem, qnames, namespaces, **kwargs)
ET._serialize_xml = ET._serialize["xml"] = _serialize_xml
# end of tweaks
def structure_payload(data):
payload = {
"status": "ok",
......@@ -56,7 +79,7 @@ def dict_to_xml_tree(root_tag, d, parent=None):
if key == "value":
root.text = str(value)
elif key == "cdata_value":
root.text = "<![CDATA[{}]]>".format(str(value))
root.append(CDATA(value))
else:
root.set(key, str(value))
return root
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment