summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-09-16 19:56:28 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-09-16 19:57:14 (GMT)
commit26d2766be47b8c5643dd7e922a0d16576e810dae (patch)
treed7a57ecd95f44ba5e1fb35c280ee89f83f5f9804 /Swiften/Serializer/PayloadSerializers
parente6305de74271ed4dd526888a217388f825d3b8fb (diff)
downloadswift-26d2766be47b8c5643dd7e922a0d16576e810dae.zip
swift-26d2766be47b8c5643dd7e922a0d16576e810dae.tar.bz2
Don't assert on untyped form fields.
Resolves: #567
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers')
-rw-r--r--Swiften/Serializer/PayloadSerializers/FormSerializer.cpp12
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp11
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));
}
};