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
640c9474
Commit
640c9474
authored
Oct 04, 2016
by
Adam Cozzette
Committed by
GitHub
Oct 04, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2204 from acozzette/enum-names
Do strict enum name checking only for proto3
parents
858db7a2
149659b7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
9 deletions
+27
-9
descriptor.cc
src/google/protobuf/descriptor.cc
+14
-5
descriptor_unittest.cc
src/google/protobuf/descriptor_unittest.cc
+13
-4
No files found.
src/google/protobuf/descriptor.cc
View file @
640c9474
...
...
@@ -4707,11 +4707,20 @@ void DescriptorBuilder::CheckEnumValueUniqueness(
// stripping should de-dup the labels in this case).
if
(
!
inserted
&&
insert_result
.
first
->
second
->
name
()
!=
value
->
name
()
&&
insert_result
.
first
->
second
->
number
()
!=
value
->
number
())
{
AddError
(
value
->
full_name
(),
proto
.
value
(
i
),
DescriptorPool
::
ErrorCollector
::
NAME
,
"When enum name is stripped and label is PascalCased ("
+
stripped
+
"), this value label conflicts with "
+
values
[
stripped
]
->
name
());
string
error_message
=
"When enum name is stripped and label is PascalCased ("
+
stripped
+
"), this value label conflicts with "
+
values
[
stripped
]
->
name
()
+
". This will make the proto fail to compile for some languages, such "
"as C#."
;
// There are proto2 enums out there with conflicting names, so to preserve
// compatibility we issue only a warning for proto2.
if
(
result
->
file
()
->
syntax
()
==
FileDescriptor
::
SYNTAX_PROTO2
)
{
AddWarning
(
value
->
full_name
(),
proto
.
value
(
i
),
DescriptorPool
::
ErrorCollector
::
NAME
,
error_message
);
}
else
{
AddError
(
value
->
full_name
(),
proto
.
value
(
i
),
DescriptorPool
::
ErrorCollector
::
NAME
,
error_message
);
}
}
}
}
...
...
src/google/protobuf/descriptor_unittest.cc
View file @
640c9474
...
...
@@ -5565,6 +5565,7 @@ TEST_F(ValidationErrorTest, MapEntryConflictsWithEnum) {
TEST_F
(
ValidationErrorTest
,
EnumValuesConflictWhenPrefixesStripped
)
{
BuildFileWithErrors
(
"syntax: 'proto3'"
"name: 'foo.proto' "
"enum_type {"
" name: 'FooEnum' "
...
...
@@ -5572,9 +5573,11 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) {
" value { name: 'BAZ' number: 1 }"
"}"
,
"foo.proto: BAZ: NAME: When enum name is stripped and label is "
"PascalCased (Baz), this value label conflicts with FOO_ENUM_BAZ
\n
"
);
"PascalCased (Baz), this value label conflicts with FOO_ENUM_BAZ. This "
"will make the proto fail to compile for some languages, such as C#.
\n
"
);
BuildFileWithErrors
(
"syntax: 'proto3'"
"name: 'foo.proto' "
"enum_type {"
" name: 'FooEnum' "
...
...
@@ -5582,9 +5585,11 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) {
" value { name: 'BAZ' number: 1 }"
"}"
,
"foo.proto: BAZ: NAME: When enum name is stripped and label is "
"PascalCased (Baz), this value label conflicts with FOOENUM_BAZ
\n
"
);
"PascalCased (Baz), this value label conflicts with FOOENUM_BAZ. This "
"will make the proto fail to compile for some languages, such as C#.
\n
"
);
BuildFileWithErrors
(
"syntax: 'proto3'"
"name: 'foo.proto' "
"enum_type {"
" name: 'FooEnum' "
...
...
@@ -5593,9 +5598,11 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) {
"}"
,
"foo.proto: BAR__BAZ: NAME: When enum name is stripped and label is "
"PascalCased (BarBaz), this value label conflicts with "
"FOO_ENUM_BAR_BAZ
\n
"
);
"FOO_ENUM_BAR_BAZ. This "
"will make the proto fail to compile for some languages, such as C#.
\n
"
);
BuildFileWithErrors
(
"syntax: 'proto3'"
"name: 'foo.proto' "
"enum_type {"
" name: 'FooEnum' "
...
...
@@ -5604,11 +5611,13 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) {
"}"
,
"foo.proto: BAR_BAZ: NAME: When enum name is stripped and label is "
"PascalCased (BarBaz), this value label conflicts with "
"FOO_ENUM__BAR_BAZ
\n
"
);
"FOO_ENUM__BAR_BAZ. This "
"will make the proto fail to compile for some languages, such as C#.
\n
"
);
// This isn't an error because the underscore will cause the PascalCase to
// differ by case (BarBaz vs. Barbaz).
BuildFile
(
"syntax: 'proto3'"
"name: 'foo.proto' "
"enum_type {"
" name: 'FooEnum' "
...
...
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