Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72000 - in trunk: boost/property_tree/detail libs/property_tree/test
From: sebastian.redl_at_[hidden]
Date: 2011-05-16 16:58:02


Author: cornedbee
Date: 2011-05-16 16:58:01 EDT (Mon, 16 May 2011)
New Revision: 72000
URL: http://svn.boost.org/trac/boost/changeset/72000

Log:
Make PTree XML writer escape attribute values.
Text files modified:
   trunk/boost/property_tree/detail/xml_parser_write.hpp | 7 +++++--
   trunk/libs/property_tree/test/test_xml_parser_common.hpp | 7 +++++++
   trunk/libs/property_tree/test/xml_parser_test_data.hpp | 5 +++++
   3 files changed, 17 insertions(+), 2 deletions(-)

Modified: trunk/boost/property_tree/detail/xml_parser_write.hpp
==============================================================================
--- trunk/boost/property_tree/detail/xml_parser_write.hpp (original)
+++ trunk/boost/property_tree/detail/xml_parser_write.hpp 2011-05-16 16:58:01 EDT (Mon, 16 May 2011)
@@ -115,8 +115,11 @@
                 // Write attributes
                 if (optional<const Ptree &> attribs = pt.get_child_optional(xmlattr<Ch>()))
                     for (It it = attribs.get().begin(); it != attribs.get().end(); ++it)
- stream << Ch(' ') << it->first << Ch('=') <<
- Ch('"') << it->second.template get_value<std::basic_string<Ch> >() << Ch('"');
+ stream << Ch(' ') << it->first << Ch('=')
+ << Ch('"')
+ << encode_char_entities(
+ it->second.template get_value<std::basic_string<Ch> >())
+ << Ch('"');
 
                 if ( has_attrs_only )
                 {

Modified: trunk/libs/property_tree/test/test_xml_parser_common.hpp
==============================================================================
--- trunk/libs/property_tree/test/test_xml_parser_common.hpp (original)
+++ trunk/libs/property_tree/test/test_xml_parser_common.hpp 2011-05-16 16:58:01 EDT (Mon, 16 May 2011)
@@ -139,6 +139,13 @@
         3, 4 * umlautsize<char_type>(), 13
     );
 
+ generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
+ (
+ ReadFuncWS(), WriteFuncWS(), bug_data_pr4840, NULL,
+ "testpr4840.xml", NULL, "testpr4840out.xml",
+ 4, 13, 15
+ );
+
 }
 
 #endif

Modified: trunk/libs/property_tree/test/xml_parser_test_data.hpp
==============================================================================
--- trunk/libs/property_tree/test/xml_parser_test_data.hpp (original)
+++ trunk/libs/property_tree/test/xml_parser_test_data.hpp 2011-05-16 16:58:01 EDT (Mon, 16 May 2011)
@@ -773,4 +773,9 @@
     "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
     "<name>\xD0\xAE\xD0\xBD\xD0\xB8\xD1\x82</name>";
 
+// Quoting attributes
+const char *bug_data_pr4840 =
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<start a=\"hello &quot;world&quot;\"/>";
+
 #endif


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk