From 26d2766be47b8c5643dd7e922a0d16576e810dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Thu, 16 Sep 2010 21:56:28 +0200 Subject: Don't assert on untyped form fields. Resolves: #567 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 FormSerializer::fieldToXML(boost::shared_ptr(field)->getValue(), "value", fieldElement); } + else if (boost::dynamic_pointer_cast(field)) { + std::vector lines = boost::dynamic_pointer_cast(field)->getValue(); + foreach(const String& line, lines) { + boost::shared_ptr 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 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 values2; + values2.push_back("foo"); + values2.push_back("bar"); + field = UntypedFormField::create(values2); + field->setName("fum"); + form->addField(field); + CPPUNIT_ASSERT_EQUAL(String( "" "" @@ -132,6 +139,10 @@ class FormSerializerTest : public CppUnit::TestFixture { "foo@bar.com" "baz@fum.org" "" + "" + "foo" + "bar" + "" ""), testling.serialize(form)); } }; -- cgit v0.10.2-6-g49f6