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
ctx->lastChild= ctx->lastAsText = textnode;
}
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;
static void CommentHnd(void *userData, const char *data)
{
wxXmlParsingContext *ctx = (wxXmlParsingContext*)userData;
XML_SetUserData(parser, (void*)&ctx);
XML_SetElementHandler(parser, StartElementHnd, EndElementHnd);
XML_SetCharacterDataHandler(parser, TextHnd);
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);
XML_SetCommentHandler(parser, CommentHnd);
XML_SetDefaultHandler(parser, DefaultHnd);
XML_SetUnknownEncodingHandler(parser, UnknownEncodingHnd, NULL);
n = n->GetChildren();
CPPUNIT_ASSERT( n );
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() );