Commit 7d700825 authored by Wouter van Oortmerssen's avatar Wouter van Oortmerssen

Merge pull request #3706 from evolutional/fix-3506

Check (& skip) of the utf-8 byte order mark
parents 8472b5f2 cbe8747b
...@@ -444,6 +444,7 @@ private: ...@@ -444,6 +444,7 @@ private:
FLATBUFFERS_CHECKED_ERROR Error(const std::string &msg); FLATBUFFERS_CHECKED_ERROR Error(const std::string &msg);
FLATBUFFERS_CHECKED_ERROR ParseHexNum(int nibbles, int64_t *val); FLATBUFFERS_CHECKED_ERROR ParseHexNum(int nibbles, int64_t *val);
FLATBUFFERS_CHECKED_ERROR Next(); FLATBUFFERS_CHECKED_ERROR Next();
FLATBUFFERS_CHECKED_ERROR SkipByteOrderMark();
bool Is(int t); bool Is(int t);
FLATBUFFERS_CHECKED_ERROR Expect(int t); FLATBUFFERS_CHECKED_ERROR Expect(int t);
std::string TokenToStringId(int t); std::string TokenToStringId(int t);
......
...@@ -200,6 +200,14 @@ CheckedError Parser::ParseHexNum(int nibbles, int64_t *val) { ...@@ -200,6 +200,14 @@ CheckedError Parser::ParseHexNum(int nibbles, int64_t *val) {
return NoError(); return NoError();
} }
CheckedError Parser::SkipByteOrderMark() {
if (static_cast<unsigned char>(*cursor_) != 0xef) return NoError();
cursor_++;
if (static_cast<unsigned char>(*cursor_++) != 0xbb) return Error("invalid utf-8 byte order mark");
if (static_cast<unsigned char>(*cursor_++) != 0xbf) return Error("invalid utf-8 byte order mark");
return NoError();
}
CheckedError Parser::Next() { CheckedError Parser::Next() {
doc_comment_.clear(); doc_comment_.clear();
bool seen_newline = false; bool seen_newline = false;
...@@ -1588,6 +1596,7 @@ CheckedError Parser::DoParse(const char *source, const char **include_paths, ...@@ -1588,6 +1596,7 @@ CheckedError Parser::DoParse(const char *source, const char **include_paths,
builder_.Clear(); builder_.Clear();
// Start with a blank namespace just in case this file doesn't have one. // Start with a blank namespace just in case this file doesn't have one.
namespaces_.push_back(new Namespace()); namespaces_.push_back(new Namespace());
ECHECK(SkipByteOrderMark());
NEXT(); NEXT();
// Includes must come before type declarations: // Includes must come before type declarations:
for (;;) { for (;;) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment