Boost C++ Libraries: Ticket #10338: Boost.PropertyTree update to v1.56 breaks existing code https://svn.boost.org/trac10/ticket/10338 <p> Commit 4e7aa973f95b7151282ebcb77dd4cb9316fe920c ("Escape newlines and tabs in content when writing XML.") has broken my code. Under certain circumstances, write_xml now produces an XML that starts with: &lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&amp;#10;&lt;Level_2&gt;&lt;Item&gt;0&lt;/Item&gt;&lt;/Level_2&gt; which cannot be parsed by read_xml (an exception is thrown). Version 1.55 did not have this issue as it did not produce the escape sequence that read_xml chokes on. </p> <p> Below I have included a unit test that reproduces the problem. </p> <p> BOOST_AUTO_TEST_CASE(<a class="missing wiki">ReadAndWriteWithSpecialCharacters</a>) { </p> <blockquote> <p> using boost::property_tree::ptree; </p> </blockquote> <blockquote> <p> <em> the xml that will be turned into a ptree. Note the linefeed between Level_1 and Level_2 tags std::string <a class="missing wiki">XmlString</a> = "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;&lt;Level_1&gt;\n&lt;Level_2&gt;&lt;Item&gt;0&lt;/Item&gt;&lt;/Level_2&gt;&lt;/Level_1&gt;"; </em></p> </blockquote> <blockquote> <p> std::stringstream StringStream1(<a class="missing wiki">XmlString</a>); std::stringstream StringStream2; </p> </blockquote> <blockquote> <p> <em> read the xml string ptree Level1Tree; read_xml(StringStream1,Level1Tree); </em></p> </blockquote> <blockquote> <p> <em> write the sub-tree at level 1 to string stream 2 as an xml ptree Level2Tree = Level1Tree.get_child("Level_1"); write_xml(StringStream2,Level2Tree); </em></p> </blockquote> <blockquote> <p> <em> show that the xml string has an xml declaration followed by \n&amp;#10; (boost version 1.56) </em> or an xml declaration followed by \n\n (boost version 1.55 and earlier) std::string Level2XmlString = StringStream2.str(); </p> </blockquote> <blockquote> <p> if (BOOST_VERSION &gt;= 105600) { </p> <blockquote> <p> BOOST_CHECK(Level2XmlString == "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&amp;#10;&lt;Level_2&gt;&lt;Item&gt;0&lt;/Item&gt;&lt;/Level_2&gt;"); </p> </blockquote> <p> } else { </p> <blockquote> <p> BOOST_CHECK(Level2XmlString == "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n\n&lt;Level_2&gt;&lt;Item&gt;0&lt;/Item&gt;&lt;/Level_2&gt;"); </p> </blockquote> <p> } </p> </blockquote> <blockquote> <p> <em> reading the xml from string stream 2 throws an exception in boost 1.56 but not in boost 1.55 ptree <a class="missing wiki">OutputTree</a>; BOOST_CHECK_NO_THROW(read_xml(StringStream2,<a class="missing wiki">OutputTree</a>)); </em></p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10338 Trac 1.4.3 pbtud@… Sun, 10 Aug 2014 17:57:48 GMT attachment set https://svn.boost.org/trac10/ticket/10338 https://svn.boost.org/trac10/ticket/10338 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">Ticket10338.txt</span> </li> </ul> <p> Unit Test </p> Ticket anonymous Tue, 17 May 2016 13:29:43 GMT <link>https://svn.boost.org/trac10/ticket/10338#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10338#comment:1</guid> <description> <p> Am I correct that commit 4e7aa973f95b7151282ebcb77dd4cb9316fe920c has been reversed by now (in boost v1.61)? If so, this ticket can be closed </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sebastian Redl</dc:creator> <pubDate>Tue, 17 May 2016 18:53:29 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/10338#comment:2 https://svn.boost.org/trac10/ticket/10338#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Yes, this was reverted by 3256d3af93dc3dd368ad06c3f7356814a906a273. </p> Ticket