Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r68991 - in trunk: boost/property_tree/detail libs/property_tree/test
From: sebastian.redl_at_[hidden]
Date: 2011-02-18 11:16:26


Author: cornedbee
Date: 2011-02-18 11:16:25 EST (Fri, 18 Feb 2011)
New Revision: 68991
URL: http://svn.boost.org/trac/boost/changeset/68991

Log:
Apply patch from bug 1678 with slight modification: allow BOM in XML parsing for wide streams. Add test case.
Text files modified:
   trunk/boost/property_tree/detail/rapidxml.hpp | 18 ++++++++++++++----
   trunk/libs/property_tree/test/test_xml_parser_common.hpp | 6 ++++++
   trunk/libs/property_tree/test/xml_parser_test_data.hpp | 6 +++++-
   3 files changed, 25 insertions(+), 5 deletions(-)

Modified: trunk/boost/property_tree/detail/rapidxml.hpp
==============================================================================
--- trunk/boost/property_tree/detail/rapidxml.hpp (original)
+++ trunk/boost/property_tree/detail/rapidxml.hpp 2011-02-18 11:16:25 EST (Fri, 18 Feb 2011)
@@ -1701,16 +1701,26 @@
         ///////////////////////////////////////////////////////////////////////
         // Internal parsing functions
         
- // Parse BOM, if any
+ // Parse UTF-8 BOM, if any
         template<int Flags>
- void parse_bom(Ch *&text)
+ void parse_bom(char *&text)
         {
- // UTF-8?
             if (static_cast<unsigned char>(text[0]) == 0xEF &&
                 static_cast<unsigned char>(text[1]) == 0xBB &&
                 static_cast<unsigned char>(text[2]) == 0xBF)
             {
- text += 3; // Skip utf-8 bom
+ text += 3;
+ }
+ }
+
+ // Parse UTF-16/32 BOM, if any
+ template<int Flags>
+ void parse_bom(wchar_t *&text)
+ {
+ const wchar_t bom = 0xFEFF;
+ if (text[0] == bom)
+ {
+ ++text;
             }
         }
 

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-02-18 11:16:25 EST (Fri, 18 Feb 2011)
@@ -124,6 +124,12 @@
         ReadFuncWS(), WriteFuncWS(), bug_data_pr2855, NULL,
         "testpr2855.xml", NULL, "testpr2855out.xml", 3, 7, 14
     );
+
+ generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
+ (
+ ReadFuncWS(), WriteFuncWS(), bug_data_pr1678, NULL,
+ "testpr1678.xml", NULL, "testpr1678out.xml", 2, 0, 4
+ );
 
 }
 

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-02-18 11:16:25 EST (Fri, 18 Feb 2011)
@@ -761,7 +761,11 @@
     "<start>"; // XML tag not closed
 
 const char *bug_data_pr2855 =
- "<?xml version=\"1.0\" encoding\"utf-8\"?>\n"
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
     "<start> notrim</start>";
 
+// byte order mark
+const char *bug_data_pr1678 =
+ "\xEF\xBB\xBF<?xml version=\"1.0\" encoding=\"utf-8\"?><root/>";
+
 #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