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
This commit is contained in:
Vadim Zeitlin 2009-08-24 21:42:27 +00:00
parent 84e0e5265d
commit a6cf6bcfb4
2 changed files with 16 additions and 4 deletions

View File

@ -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);

View File

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