XEP-0004: fix: prevent multiple <values> for 'text-single' field
According to XEP-0004: - if there is no "type" attribute on a <field />, we should assume it is "text-single"; - "text-single" MUST NOT contain morethan one <value />. Before this patch, not specifying a field type and passing a multi-line string would result in an illegal stanza. While it would be cleaner to log a warning or even raise an exception if set_value() is called with an incompatible type, this breaks a lot of tests and backward-compatibility, so we introduce some heuristic in FormField.set_value() to infer the field type based on the provided value instead. I also changed FormField.get_value() so that it returns a list by default for 'text-multi' fields. This is a breaking change, but I have not found the justification for the previous behaviour.
This commit is contained in:
@@ -95,6 +95,21 @@ class TestDataForms(SlixTest):
|
||||
</message>
|
||||
""")
|
||||
|
||||
def testMultiLineField(self):
|
||||
msg = self.Message()
|
||||
form = msg['form']
|
||||
form.addField(var='f1',
|
||||
value='Some text\non several\n\nlines')
|
||||
self.check(msg, """
|
||||
<message>
|
||||
<x xmlns="jabber:x:data" type="form">
|
||||
<field var="f1">
|
||||
<value>Some text\non several\n\nlines</value>
|
||||
</field>
|
||||
</x>
|
||||
</message>
|
||||
""")
|
||||
|
||||
def testSetValues(self):
|
||||
"""Testing setting form values"""
|
||||
|
||||
@@ -117,7 +132,7 @@ class TestDataForms(SlixTest):
|
||||
<value>b</value>
|
||||
</field>
|
||||
</x>
|
||||
</message>""")
|
||||
</message>""", use_values=False)
|
||||
|
||||
def testSubmitType(self):
|
||||
"""Test that setting type to 'submit' clears extra details"""
|
||||
|
||||
Reference in New Issue
Block a user