From: Vadim Zeitlin Date: Mon, 24 Aug 2009 21:42:27 +0000 (+0000) Subject: Don't append text following CDATA section to its node itself. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/a6cf6bcfb46c8ba3ef5d8daef8ff1e60caaf41ac Don't append text following CDATA section to its node itself. Reset wxXmlParsingContext::lastAsText flag when CDATA section ends to avoid appending the text following it to its node. Instead new text nodes should be created for it. Also update the unit test to not work around the bug any more. Closes #10552. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61759 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/xml/xml.cpp b/src/xml/xml.cpp index a37225c3dd..1917c27ba8 100644 --- a/src/xml/xml.cpp +++ b/src/xml/xml.cpp @@ -618,6 +618,17 @@ static void StartCdataHnd(void *userData) ctx->lastChild= ctx->lastAsText = textnode; } +static void EndCdataHnd(void *userData) +{ + wxXmlParsingContext *ctx = (wxXmlParsingContext*)userData; + + // we need to reset this pointer so that subsequent text nodes don't append + // their contents to this one but create new wxXML_TEXT_NODE objects (or + // not create anything at all if only white space follows the CDATA section + // and wxXMLDOC_KEEP_WHITESPACE_NODES is not used as is commonly the case) + ctx->lastAsText = NULL; +} + static void CommentHnd(void *userData, const char *data) { wxXmlParsingContext *ctx = (wxXmlParsingContext*)userData; @@ -717,7 +728,7 @@ bool wxXmlDocument::Load(wxInputStream& stream, const wxString& encoding, int fl XML_SetUserData(parser, (void*)&ctx); XML_SetElementHandler(parser, StartElementHnd, EndElementHnd); XML_SetCharacterDataHandler(parser, TextHnd); - XML_SetStartCdataSectionHandler(parser, StartCdataHnd); + XML_SetCdataSectionHandler(parser, StartCdataHnd, EndCdataHnd);; XML_SetCommentHandler(parser, CommentHnd); XML_SetDefaultHandler(parser, DefaultHnd); XML_SetUnknownEncodingHandler(parser, UnknownEncodingHnd, NULL); diff --git a/tests/xml/xmltest.cpp b/tests/xml/xmltest.cpp index d8cda12b03..9f3d6056a5 100644 --- a/tests/xml/xmltest.cpp +++ b/tests/xml/xmltest.cpp @@ -210,7 +210,8 @@ void XmlTestCase::CDATA() n = n->GetChildren(); CPPUNIT_ASSERT( n ); - // currently leading white space is stripped by trailing is preserved (see - // #10552) - CPPUNIT_ASSERT_EQUAL( "Giovanni Mittone\n", n->GetContent() ); + // check that both leading (" ") and trailing white space is not part of + // the node contents when CDATA is used and wxXMLDOC_KEEP_WHITESPACE_NODES + // is not + CPPUNIT_ASSERT_EQUAL( "Giovanni Mittone", n->GetContent() ); }