diff options
Diffstat (limited to 'Swiften/Serializer')
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/FormSerializer.cpp | 12 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp | 11 |
2 files changed, 22 insertions, 1 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp b/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp index e82f2d0..ece8fd8 100644 --- a/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp @@ -128,10 +128,20 @@ boost::shared_ptr<XMLElement> FormSerializer::fieldToXML(boost::shared_ptr<FormF fieldType = "text-multi"; multiLineify(boost::dynamic_pointer_cast<TextMultiFormField>(field)->getValue(), "value", fieldElement); } + else if (boost::dynamic_pointer_cast<UntypedFormField>(field)) { + std::vector<String> lines = boost::dynamic_pointer_cast<UntypedFormField>(field)->getValue(); + foreach(const String& line, lines) { + boost::shared_ptr<XMLElement> valueElement(new XMLElement("value")); + valueElement->addNode(XMLTextNode::create(line)); + fieldElement->addNode(valueElement); + } + } else { assert(false); } - fieldElement->setAttribute("type", fieldType); + if (!fieldType.isEmpty()) { + fieldElement->setAttribute("type", fieldType); + } foreach (const FormField::Option& option, field->getOptions()) { boost::shared_ptr<XMLElement> optionElement(new XMLElement("option")); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp index 0d98dea..ebc8664 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp @@ -96,6 +96,13 @@ class FormSerializerTest : public CppUnit::TestFixture { field->setDescription("Tell all your friends about your new bot!"); form->addField(field); + std::vector<String> values2; + values2.push_back("foo"); + values2.push_back("bar"); + field = UntypedFormField::create(values2); + field->setName("fum"); + form->addField(field); + CPPUNIT_ASSERT_EQUAL(String( "<x type=\"form\" xmlns=\"jabber:x:data\">" "<field type=\"hidden\" var=\"FORM_TYPE\">" @@ -132,6 +139,10 @@ class FormSerializerTest : public CppUnit::TestFixture { "<value>foo@bar.com</value>" "<value>baz@fum.org</value>" "</field>" + "<field var=\"fum\">" + "<value>foo</value>" + "<value>bar</value>" + "</field>" "</x>"), testling.serialize(form)); } }; |