@@ -871,6 +871,7 @@ class OurFeatures {
871871 bool failIfExtra_;
872872 bool rejectDupKeys_;
873873 bool allowSpecialFloats_;
874+ bool allowBom_;
874875 size_t stackLimit_;
875876}; // OurFeatures
876877
@@ -939,7 +940,7 @@ class OurReader {
939940
940941 bool readToken (Token& token);
941942 void skipSpaces ();
942- void skipBom ();
943+ void skipBom (bool allowBom );
943944 bool match (const Char* pattern, int patternLength);
944945 bool readComment ();
945946 bool readCStyleComment (bool * containsNewLineResult);
@@ -1024,7 +1025,7 @@ bool OurReader::parse(const char* beginDoc, const char* endDoc, Value& root,
10241025 nodes_.push (&root);
10251026
10261027 // skip byte order mark if it exists at the beginning of the UTF-8 text.
1027- skipBom ();
1028+ skipBom (features_. allowBom_ );
10281029 bool successful = readValue ();
10291030 nodes_.pop ();
10301031 Token token;
@@ -1271,10 +1272,14 @@ void OurReader::skipSpaces() {
12711272 }
12721273}
12731274
1274- void OurReader::skipBom () {
1275- if (strncmp (begin_, " \xEF\xBB\xBF " , 3 ) == 0 ) {
1276- begin_ += 3 ;
1277- current_ = begin_;
1275+ void OurReader::skipBom (bool allowBom) {
1276+ // If BOM is not allowed, then skip it.
1277+ // The default value is: false
1278+ if (!allowBom) {
1279+ if (strncmp (begin_, " \xEF\xBB\xBF " , 3 ) == 0 ) {
1280+ begin_ += 3 ;
1281+ current_ = begin_;
1282+ }
12781283 }
12791284}
12801285
@@ -1895,6 +1900,7 @@ CharReader* CharReaderBuilder::newCharReader() const {
18951900 features.failIfExtra_ = settings_[" failIfExtra" ].asBool ();
18961901 features.rejectDupKeys_ = settings_[" rejectDupKeys" ].asBool ();
18971902 features.allowSpecialFloats_ = settings_[" allowSpecialFloats" ].asBool ();
1903+ features.allowBom_ = settings_[" allowBom" ].asBool ();
18981904 return new OurCharReader (collectComments, features);
18991905}
19001906static void getValidReaderKeys (std::set<String>* valid_keys) {
@@ -1910,6 +1916,7 @@ static void getValidReaderKeys(std::set<String>* valid_keys) {
19101916 valid_keys->insert (" failIfExtra" );
19111917 valid_keys->insert (" rejectDupKeys" );
19121918 valid_keys->insert (" allowSpecialFloats" );
1919+ valid_keys->insert (" allowBom" );
19131920}
19141921bool CharReaderBuilder::validate (Json::Value* invalid) const {
19151922 Json::Value my_invalid;
@@ -1944,6 +1951,7 @@ void CharReaderBuilder::strictMode(Json::Value* settings) {
19441951 (*settings)[" failIfExtra" ] = true ;
19451952 (*settings)[" rejectDupKeys" ] = true ;
19461953 (*settings)[" allowSpecialFloats" ] = false ;
1954+ (*settings)[" allowBom" ] = false ;
19471955 // ! [CharReaderBuilderStrictMode]
19481956}
19491957// static
@@ -1960,6 +1968,7 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
19601968 (*settings)[" failIfExtra" ] = false ;
19611969 (*settings)[" rejectDupKeys" ] = false ;
19621970 (*settings)[" allowSpecialFloats" ] = false ;
1971+ (*settings)[" allowBom" ] = false ;
19631972 // ! [CharReaderBuilderDefaults]
19641973}
19651974
0 commit comments