Subject: [Boost-bugs] [Boost C++ Libraries] #4809: deserialization with xml_iarchive fails when attributes of top level element are reordered
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-11-02 15:47:59
#4809: deserialization with xml_iarchive fails when attributes of top level
element are reordered
-----------------------------------------------+----------------------------
Reporter: Kolja Nowak <kolja@â¦> | Owner:
Type: Bugs | Status: new
Milestone: To Be Determined | Component: None
Version: Boost 1.44.0 | Severity: Problem
Keywords: serialization xml attribute order |
-----------------------------------------------+----------------------------
Citing from [http://www.w3.org/TR/2008/REC-xml-20081126/ W3C XML spec],
section 3.1: "Note that the order of attribute specifications in a start-
tag or empty-element tag is not significant."
The parser used by xml_iarchive doesn't conform to this, because it fails
on XML input which is logically equivalent to the output of xml_oarchive,
just because the attribute order of the top level element
'boost_serialization' was changed. In contrast, the parser seems to be
robust against reordering attributes in other elements.
The following program demonstrates the issue:
{{{
#include <iostream>
#include <sstream>
#include <string>
#include <boost/archive/xml_iarchive.hpp>
void f(const std::string& xml)
{
try
{
std::string str;
boost::archive::xml_iarchive(std::istringstream(xml))
>> boost::serialization::make_nvp("str", str);
std::cout << str << std::endl;
}
catch(boost::archive::archive_exception& e)
{
std::cout << e.what() << std::endl;
}
}
int main()
{
// deserialize some xml, which was created using xml_oarchive
f("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>"
"<!DOCTYPE boost_serialization>"
"<boost_serialization signature=\"serialization::archive\"
version=\"7\">"
"<str>deserialize successfull</str>"
"</boost_serialization>");
// the same xml, but attributes of <boost_serialization> reorderd
f("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>"
"<!DOCTYPE boost_serialization>"
"<boost_serialization version=\"7\"
signature=\"serialization::archive\">"
"<str>deserialize successfull</str>"
"</boost_serialization>");
return 0;
}
}}}
The following patch to basic_xml_grammar.ipp modifies the rule
'SerializationWrapper' to accept both possible combinations:
{{{
Index: libs/serialization/src/basic_xml_grammar.ipp
===================================================================
--- libs/serialization/src/basic_xml_grammar.ipp (revision 66354)
+++ libs/serialization/src/basic_xml_grammar.ipp (working copy)
@@ -271,9 +271,9 @@
= -S
>> "<boost_serialization"
>> S
- >> SignatureAttribute
- >> S
- >> VersionAttribute
+ >> ( (SignatureAttribute >> S >> VersionAttribute)
+ | (VersionAttribute >> S >> SignatureAttribute)
+ )
>> !S
>> '>'
;
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/4809> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:04 UTC