diff options
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Parser/LibXMLParser.cpp | 13 | ||||
-rw-r--r-- | Swiften/Parser/UnitTest/XMLParserTest.cpp | 17 |
2 files changed, 28 insertions, 2 deletions
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<XMLParserClient*>(client)->handleCharacterData(String(reinterpret_cast<const char*>(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( + "<query xmlns='http://www.xmpp.org/extensions/xep-0084.html#ns-data '>")); + CPPUNIT_ASSERT(testling.parse( + "<presence/>")); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(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 { |