Opened 8 years ago
Closed 6 years ago
#10338 closed Bugs (fixed)
Boost.PropertyTree update to v1.56 breaks existing code
Reported by: | Pieter | Owned by: | Sebastian Redl |
---|---|---|---|
Milestone: | To Be Determined | Component: | property_tree |
Version: | Boost 1.56.0 | Severity: | Regression |
Keywords: | Escape sequence problem | Cc: |
Description
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: <?xml version=\"1.0\" encoding=\"utf-8\"?>\n <Level_2><Item>0</Item></Level_2> 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.
Below I have included a unit test that reproduces the problem.
BOOST_AUTO_TEST_CASE(ReadAndWriteWithSpecialCharacters) {
using boost::property_tree::ptree;
the xml that will be turned into a ptree. Note the linefeed between Level_1 and Level_2 tags std::string XmlString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Level_1>\n<Level_2><Item>0</Item></Level_2></Level_1>";
std::stringstream StringStream1(XmlString); std::stringstream StringStream2;
read the xml string ptree Level1Tree; read_xml(StringStream1,Level1Tree);
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);
show that the xml string has an xml declaration followed by \n (boost version 1.56) or an xml declaration followed by \n\n (boost version 1.55 and earlier) std::string Level2XmlString = StringStream2.str();
if (BOOST_VERSION >= 105600) {
BOOST_CHECK(Level2XmlString == "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n <Level_2><Item>0</Item></Level_2>");
} else {
BOOST_CHECK(Level2XmlString == "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n<Level_2><Item>0</Item></Level_2>");
}
reading the xml from string stream 2 throws an exception in boost 1.56 but not in boost 1.55 ptree OutputTree; BOOST_CHECK_NO_THROW(read_xml(StringStream2,OutputTree));
}
Attachments (1)
Change History (3)
by , 8 years ago
Attachment: | Ticket10338.txt added |
---|
comment:1 by , 6 years ago
Am I correct that commit 4e7aa973f95b7151282ebcb77dd4cb9316fe920c has been reversed by now (in boost v1.61)? If so, this ticket can be closed
comment:2 by , 6 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Yes, this was reverted by 3256d3af93dc3dd368ad06c3f7356814a906a273.
Unit Test