Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
76488525
Commit
76488525
authored
Jul 17, 2015
by
Jie Luo
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #601 from anandolee/master
ignore UTF-8 BOM
parents
2f4fb642
b2d2cf8b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
parser_unittest.cc
src/google/protobuf/compiler/parser_unittest.cc
+26
-0
tokenizer.cc
src/google/protobuf/io/tokenizer.cc
+9
-0
No files found.
src/google/protobuf/compiler/parser_unittest.cc
View file @
76488525
...
...
@@ -229,6 +229,32 @@ TEST_F(ParserTest, WarnIfSyntaxIdentifierOmmitted) {
typedef
ParserTest
ParseMessageTest
;
TEST_F
(
ParseMessageTest
,
IgnoreBOM
)
{
char
input
[]
=
" message TestMessage {
\n
"
" required int32 foo = 1;
\n
"
"}
\n
"
;
// Set UTF-8 BOM.
input
[
0
]
=
(
char
)
0xEF
;
input
[
1
]
=
(
char
)
0xBB
;
input
[
2
]
=
(
char
)
0xBF
;
ExpectParsesTo
(
input
,
"message_type {"
" name:
\"
TestMessage
\"
"
" field { name:
\"
foo
\"
label:LABEL_REQUIRED type:TYPE_INT32 number:1 }"
"}"
);
}
TEST_F
(
ParseMessageTest
,
BOMError
)
{
char
input
[]
=
" message TestMessage {
\n
"
" required int32 foo = 1;
\n
"
"}
\n
"
;
input
[
0
]
=
(
char
)
0xEF
;
ExpectHasErrors
(
input
,
"0:1: Proto file starts with 0xEF but not UTF-8 BOM. "
"Only UTF-8 is accepted for proto file.
\n
"
"0:0: Expected top-level statement (e.g.
\"
message
\"
).
\n
"
);
}
TEST_F
(
ParseMessageTest
,
SimpleMessage
)
{
ExpectParsesTo
(
"message TestMessage {
\n
"
...
...
src/google/protobuf/io/tokenizer.cc
View file @
76488525
...
...
@@ -762,6 +762,15 @@ bool Tokenizer::NextWithComments(string* prev_trailing_comments,
next_leading_comments
);
if
(
current_
.
type
==
TYPE_START
)
{
// Ignore unicode byte order mark(BOM) if it appears at the file
// beginning. Only UTF-8 BOM (0xEF 0xBB 0xBF) is accepted.
if
(
TryConsume
((
char
)
0xEF
))
{
if
(
!
TryConsume
((
char
)
0xBB
)
||
!
TryConsume
((
char
)
0xBF
))
{
AddError
(
"Proto file starts with 0xEF but not UTF-8 BOM. "
"Only UTF-8 is accepted for proto file."
);
return
false
;
}
}
collector
.
DetachFromPrev
();
}
else
{
// A comment appearing on the same line must be attached to the previous
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment