From eb788bf484f4d11f524473986bf19d1a80f522bc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Tue, 12 Oct 2010 18:20:23 +0200
Subject: Don't assert on incorrect priorities.

Release-Notes: We don't crash anymore when a contact has set an incorrect priority

diff --git a/Documentation/SwiftenDevelopersGuide/documentation.css b/Documentation/SwiftenDevelopersGuide/documentation.css
index 937a6ac..5b93a3e 100644
--- a/Documentation/SwiftenDevelopersGuide/documentation.css
+++ b/Documentation/SwiftenDevelopersGuide/documentation.css
@@ -1,30 +1,30 @@
-html{
-    font-family: "Lucida Grande", "Segoe UI", sans-serif;
-    color: #111;
-    background: #EEE;
-    font-size: 62.5%;
-}
-
-body{
-    width: 640px;
-    float: left;
-    margin: 20px;
+html{
+    font-family: "Lucida Grande", "Segoe UI", sans-serif;
+    color: #111;
+    background: #EEE;
+    font-size: 62.5%;
+}
+
+body{
+    width: 640px;
+    float: left;
+    margin: 20px;
     padding: 10px 30px;
-    font-size: 1.3em;
-    line-height: 1.5em;
-}
-
-a{
-    color: #669;
-}
-
-a:visited{
-    color: #444;
-}
-
-a:hover{
-    color: #000;
-}
+    font-size: 1.3em;
+    line-height: 1.5em;
+}
+
+a{
+    color: #669;
+}
+
+a:visited{
+    color: #444;
+}
+
+a:hover{
+    color: #000;
+}
 
 pre {
 	background: #EEE;
diff --git a/Swiften/Parser/PayloadParsers/PriorityParser.cpp b/Swiften/Parser/PayloadParsers/PriorityParser.cpp
index 7bf81bf..8872977 100644
--- a/Swiften/Parser/PayloadParsers/PriorityParser.cpp
+++ b/Swiften/Parser/PayloadParsers/PriorityParser.cpp
@@ -20,7 +20,13 @@ void PriorityParser::handleStartElement(const String&, const String&, const Attr
 void PriorityParser::handleEndElement(const String&, const String&) {
 	--level_;
 	if (level_ == 0) {
-		getPayloadInternal()->setPriority(boost::lexical_cast<int>(text_));
+		int priority = 0;
+		try {
+			priority = boost::lexical_cast<int>(text_);
+		}
+		catch (boost::bad_lexical_cast& e) {
+		}
+		getPayloadInternal()->setPriority(priority);
 	}
 }
 
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp
index 7c18762..b340739 100644
--- a/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp
+++ b/Swiften/Parser/PayloadParsers/UnitTest/PriorityParserTest.cpp
@@ -12,15 +12,13 @@
 
 using namespace Swift;
 
-class PriorityParserTest : public CppUnit::TestFixture
-{
+class PriorityParserTest : public CppUnit::TestFixture {
 		CPPUNIT_TEST_SUITE(PriorityParserTest);
 		CPPUNIT_TEST(testParse);
+		CPPUNIT_TEST(testParse_Invalid);
 		CPPUNIT_TEST_SUITE_END();
 
 	public:
-		PriorityParserTest() {}
-
 		void testParse() {
 			PayloadsParserTester parser;
 
@@ -29,6 +27,15 @@ class PriorityParserTest : public CppUnit::TestFixture
 			Priority* payload = dynamic_cast<Priority*>(parser.getPayload().get());
 			CPPUNIT_ASSERT_EQUAL(-120, payload->getPriority());
 		}
+
+		void testParse_Invalid() {
+			PayloadsParserTester parser;
+
+			CPPUNIT_ASSERT(parser.parse("<priority>invalid</priority>"));
+
+			Priority* payload = dynamic_cast<Priority*>(parser.getPayload().get());
+			CPPUNIT_ASSERT_EQUAL(0, payload->getPriority());
+		}
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(PriorityParserTest);
-- 
cgit v0.10.2-6-g49f6