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() ); }