$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r75003 - in trunk/boost/test: impl utils
From: gennadiy.rozental_at_[hidden]
Date: 2011-10-17 01:26:08
Author: rogeeff
Date: 2011-10-17 01:26:05 EDT (Mon, 17 Oct 2011)
New Revision: 75003
URL: http://svn.boost.org/trac/boost/changeset/75003
Log:
escape CDATA section end within CDATA section
Fixes #5412
Text files modified: 
   trunk/boost/test/impl/xml_log_formatter.ipp |     4 ++--                                    
   trunk/boost/test/utils/xml_printer.hpp      |    20 +++++++++++++++++++-                    
   2 files changed, 21 insertions(+), 3 deletions(-)
Modified: trunk/boost/test/impl/xml_log_formatter.ipp
==============================================================================
--- trunk/boost/test/impl/xml_log_formatter.ipp	(original)
+++ trunk/boost/test/impl/xml_log_formatter.ipp	2011-10-17 01:26:05 EDT (Mon, 17 Oct 2011)
@@ -158,7 +158,7 @@
 void
 xml_log_formatter::log_entry_value( std::ostream& ostr, const_string value )
 {
-    ostr << value;
+    print_escaped_cdata( ostr, value );
 }
 
 //____________________________________________________________________________//
@@ -203,7 +203,7 @@
 void
 xml_log_formatter::log_entry_context( std::ostream& ostr, const_string context_descr )
 {
-    ostr << BOOST_TEST_L( "<Frame><![CDATA[" ) << context_descr << BOOST_TEST_L( "]]></Frame>" );
+    ostr << BOOST_TEST_L( "<Frame>" ) << cdata() << context_descr << BOOST_TEST_L( "</Frame>" );
 }
 
 //____________________________________________________________________________//
Modified: trunk/boost/test/utils/xml_printer.hpp
==============================================================================
--- trunk/boost/test/utils/xml_printer.hpp	(original)
+++ trunk/boost/test/utils/xml_printer.hpp	2011-10-17 01:26:05 EDT (Mon, 17 Oct 2011)
@@ -81,6 +81,22 @@
 
 //____________________________________________________________________________//
 
+inline void
+print_escaped_cdata( std::ostream& where_to, const_string value )
+{
+    static const_string cdata_end( "]]>" );
+    
+    const_string::size_type pos = value.find( cdata_end );
+    if( pos == const_string::npos )
+        where_to << value;
+    else {
+        where_to << value.substr( 0, pos+2 ) << cdata_end 
+                 << BOOST_TEST_L( "<![CDATA[" ) << value.substr( pos+2 );
+    }
+}
+
+//____________________________________________________________________________//
+
 typedef custom_manip<struct attr_value_t> attr_value;
 
 template<typename T>
@@ -101,7 +117,9 @@
 inline std::ostream&
 operator<<( custom_printer<cdata> const& p, const_string value )
 {
-    return *p << BOOST_TEST_L( "<![CDATA[" ) << value << BOOST_TEST_L( "]]>" );
+    *p << BOOST_TEST_L( "<![CDATA[" );
+    print_escaped_cdata( *p, value );
+    return  *p << BOOST_TEST_L( "]]>" );
 }
 
 //____________________________________________________________________________//