From be0d72c3ad4790447dfb9d0c439971cfd7dcc2fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Tue, 24 Aug 2010 18:26:33 +0200 Subject: Work around LibXML failing on namespace errors/warnings. diff --git a/Swiften/Parser/LibXMLParser.cpp b/Swiften/Parser/LibXMLParser.cpp index b5f3e53..7fe13fe 100644 --- a/Swiften/Parser/LibXMLParser.cpp +++ b/Swiften/Parser/LibXMLParser.cpp @@ -31,7 +31,7 @@ static void handleCharacterData(void* client, const xmlChar* data, int len) { static_cast(client)->handleCharacterData(String(reinterpret_cast(data), len)); } -static void handleError(void*, const char*, ... ) { +static void handleError(void*, const char* /*m*/, ... ) { /* va_list args; va_start(args, m); @@ -65,7 +65,16 @@ LibXMLParser::~LibXMLParser() { } bool LibXMLParser::parse(const String& data) { - return xmlParseChunk(context_, data.getUTF8Data(), data.getUTF8Size(), false) == XML_ERR_OK; + if (xmlParseChunk(context_, data.getUTF8Data(), data.getUTF8Size(), false) == XML_ERR_OK) { + return true; + } + xmlError* error = xmlCtxtGetLastError(context_); + if (error->code == XML_WAR_NS_URI || error->code == XML_WAR_NS_URI_RELATIVE) { + xmlCtxtResetLastError(context_); + context_->errNo = XML_ERR_OK; + return true; + } + return false; } } diff --git a/Swiften/Parser/UnitTest/XMLParserTest.cpp b/Swiften/Parser/UnitTest/XMLParserTest.cpp index 7b4b38e..2aae4cd 100644 --- a/Swiften/Parser/UnitTest/XMLParserTest.cpp +++ b/Swiften/Parser/UnitTest/XMLParserTest.cpp @@ -30,6 +30,7 @@ class XMLParserTest : public CppUnit::TestFixture { CPPUNIT_TEST(testParse_InvalidXML); CPPUNIT_TEST(testParse_InErrorState); CPPUNIT_TEST(testParse_Incremental); + CPPUNIT_TEST(testParse_WhitespaceInAttribute); CPPUNIT_TEST_SUITE_END(); public: @@ -188,6 +189,22 @@ class XMLParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[1].type); CPPUNIT_ASSERT_EQUAL(String("iq"), client_.events[1].data); } + + void testParse_WhitespaceInAttribute() { + ParserType testling(&client_); + + CPPUNIT_ASSERT(testling.parse( + "")); + CPPUNIT_ASSERT(testling.parse( + "")); + CPPUNIT_ASSERT_EQUAL(static_cast(3), client_.events.size()); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[0].type); + CPPUNIT_ASSERT_EQUAL(String("query"), client_.events[0].data); + CPPUNIT_ASSERT_EQUAL(Client::StartElement, client_.events[1].type); + CPPUNIT_ASSERT_EQUAL(String("presence"), client_.events[1].data); + CPPUNIT_ASSERT_EQUAL(Client::EndElement, client_.events[2].type); + CPPUNIT_ASSERT_EQUAL(String("presence"), client_.events[2].data); + } private: class Client : public XMLParserClient { -- cgit v0.10.2-6-g49f6