diff --git a/include/boost/property_tree/detail/xml_parser_read_rapidxml.hpp b/include/boost/property_tree/detail/xml_parser_read_rapidxml.hpp index 9c0421918..269b57d00 100644 --- a/include/boost/property_tree/detail/xml_parser_read_rapidxml.hpp +++ b/include/boost/property_tree/detail/xml_parser_read_rapidxml.hpp @@ -31,8 +31,11 @@ namespace boost { namespace property_tree { namespace xml_parser case node_element: { // Create node - Ptree &pt_node = pt.push_back(std::make_pair(node->name(), - Ptree()))->second; + Ptree &pt_node = pt.push_back(std::make_pair( + (node->name() == const_cast( + "nullkey-3cb6534e-d358-4705-9e74-fee06453661e") + ? const_cast("") : node->name()), + Ptree()))->second; // Copy attributes if (node->first_attribute()) diff --git a/include/boost/property_tree/detail/xml_parser_write.hpp b/include/boost/property_tree/detail/xml_parser_write.hpp index de95e745c..093277670 100644 --- a/include/boost/property_tree/detail/xml_parser_write.hpp +++ b/include/boost/property_tree/detail/xml_parser_write.hpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -73,6 +74,7 @@ namespace boost { namespace property_tree { namespace xml_parser typedef typename Ptree::key_type::value_type Ch; typedef typename Ptree::key_type Str; typedef typename Ptree::const_iterator It; + const typename Ptree::key_type &nullkey = "nullkey-3cb6534e-d358-4705-9e74-fee06453661e"; bool want_pretty = settings.indent_count > 0; // Find if elements present @@ -97,7 +99,8 @@ namespace boost { namespace property_tree { namespace xml_parser if (indent >= 0) { write_xml_indent(stream,indent,settings); - stream << Ch('<') << key << + stream << Ch('<') << (key.empty() ? + lexical_cast(nullkey) : key) << Ch('/') << Ch('>'); if (want_pretty) stream << Ch('\n'); @@ -110,7 +113,8 @@ namespace boost { namespace property_tree { namespace xml_parser { // Write opening brace and key write_xml_indent(stream,indent,settings); - stream << Ch('<') << key; + stream << Ch('<') << (key.empty() ? + lexical_cast(nullkey) : key); // Write attributes if (optional attribs = pt.get_child_optional(xmlattr())) @@ -168,7 +172,8 @@ namespace boost { namespace property_tree { namespace xml_parser { if (has_elements) write_xml_indent(stream,indent,settings); - stream << Ch('<') << Ch('/') << key << Ch('>'); + stream << Ch('<') << Ch('/') << (key.empty() ? + lexical_cast(nullkey) : key) << Ch('>'); if (want_pretty) stream << Ch('\n'); } diff --git a/test/test_xml_parser_common.hpp b/test/test_xml_parser_common.hpp index 019773bb6..a8ed8389f 100644 --- a/test/test_xml_parser_common.hpp +++ b/test/test_xml_parser_common.hpp @@ -107,6 +107,12 @@ void test_xml_parser() 3, umlautsize(), 12 ); + generic_parser_test_ok + ( + ReadFuncWS(), WriteFuncWS(), ok_data_6, NULL, + "testok6a.xml", NULL, "testok6aout.xml", 4, 1, 2 + ); + generic_parser_test_error ( ReadFuncWS(), WriteFuncWS(), error_data_1, NULL, diff --git a/test/xml_parser_test_data.hpp b/test/xml_parser_test_data.hpp index d0b4c071c..453e8de3a 100644 --- a/test/xml_parser_test_data.hpp +++ b/test/xml_parser_test_data.hpp @@ -747,6 +747,13 @@ const char ok_data_5[] = "\n" /*39 chars*/ "\xC3\xA4"; +const char *ok_data_6 = + "" + "" + "c" + "" + ""; + // Erroneous const char *error_data_1 = "a"; // bogus character