plugin pubsub schema: fixed XML field handling in sendDataFormItem

This commit is contained in:
Goffi 2019-11-08 12:51:03 +01:00
commit d2a51169b2

View file

@ -405,15 +405,25 @@ class PubsubSchema(object):
values_list = field.values
elif field.ext_type == 'xml':
# FIXME: XML elements are not handled correctly, we need to know if we
# actual XML/XHTML, or text to escape
# have actual XML/XHTML, or text to escape
for idx, value in enumerate(values_list[:]):
if not isinstance(value, domish.Element):
if isinstance(value, domish.Element):
if (field.value and (value.name != field.value.name
or value.uri != field.value.uri)):
# the element is not the one expected in form, so we create the right element
# to wrap the current value
wrapper_elt = domish.Element((field.value.uri, field.value.name))
wrapper_elt.addChild(value)
values_list[idx] = wrapper_elt
else:
# we have to convert the value to a domish.Element
if field.value and field.value.uri == C.NS_XHTML:
div_elt = domish.Element((C.NS_XHTML, 'div'))
div_elt.addContent(str(value))
values_list[idx] = div_elt
else:
raise NotImplementedError
else:
# only XHTML fields are handled for now
raise NotImplementedError
field.values = values_list