@@ -871,6 +871,7 @@ class OurFeatures {
871
871
bool failIfExtra_;
872
872
bool rejectDupKeys_;
873
873
bool allowSpecialFloats_;
874
+ bool allowBom_;
874
875
size_t stackLimit_;
875
876
}; // OurFeatures
876
877
@@ -939,7 +940,7 @@ class OurReader {
939
940
940
941
bool readToken (Token& token);
941
942
void skipSpaces ();
942
- void skipBom ();
943
+ void skipBom (bool allowBom );
943
944
bool match (const Char* pattern, int patternLength);
944
945
bool readComment ();
945
946
bool readCStyleComment (bool * containsNewLineResult);
@@ -1024,7 +1025,7 @@ bool OurReader::parse(const char* beginDoc, const char* endDoc, Value& root,
1024
1025
nodes_.push (&root);
1025
1026
1026
1027
// skip byte order mark if it exists at the beginning of the UTF-8 text.
1027
- skipBom ();
1028
+ skipBom (features_. allowBom_ );
1028
1029
bool successful = readValue ();
1029
1030
nodes_.pop ();
1030
1031
Token token;
@@ -1271,10 +1272,14 @@ void OurReader::skipSpaces() {
1271
1272
}
1272
1273
}
1273
1274
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
+ }
1278
1283
}
1279
1284
}
1280
1285
@@ -1895,6 +1900,7 @@ CharReader* CharReaderBuilder::newCharReader() const {
1895
1900
features.failIfExtra_ = settings_[" failIfExtra" ].asBool ();
1896
1901
features.rejectDupKeys_ = settings_[" rejectDupKeys" ].asBool ();
1897
1902
features.allowSpecialFloats_ = settings_[" allowSpecialFloats" ].asBool ();
1903
+ features.allowBom_ = settings_[" allowBom" ].asBool ();
1898
1904
return new OurCharReader (collectComments, features);
1899
1905
}
1900
1906
static void getValidReaderKeys (std::set<String>* valid_keys) {
@@ -1910,6 +1916,7 @@ static void getValidReaderKeys(std::set<String>* valid_keys) {
1910
1916
valid_keys->insert (" failIfExtra" );
1911
1917
valid_keys->insert (" rejectDupKeys" );
1912
1918
valid_keys->insert (" allowSpecialFloats" );
1919
+ valid_keys->insert (" allowBom" );
1913
1920
}
1914
1921
bool CharReaderBuilder::validate (Json::Value* invalid) const {
1915
1922
Json::Value my_invalid;
@@ -1944,6 +1951,7 @@ void CharReaderBuilder::strictMode(Json::Value* settings) {
1944
1951
(*settings)[" failIfExtra" ] = true ;
1945
1952
(*settings)[" rejectDupKeys" ] = true ;
1946
1953
(*settings)[" allowSpecialFloats" ] = false ;
1954
+ (*settings)[" allowBom" ] = false ;
1947
1955
// ! [CharReaderBuilderStrictMode]
1948
1956
}
1949
1957
// static
@@ -1960,6 +1968,7 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
1960
1968
(*settings)[" failIfExtra" ] = false ;
1961
1969
(*settings)[" rejectDupKeys" ] = false ;
1962
1970
(*settings)[" allowSpecialFloats" ] = false ;
1971
+ (*settings)[" allowBom" ] = false ;
1963
1972
// ! [CharReaderBuilderDefaults]
1964
1973
}
1965
1974
0 commit comments