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
8866d6a8
Commit
8866d6a8
authored
Jan 15, 2016
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reject JSON containing the same oneof field twice
parent
52db5139
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
JsonParserTest.cs
csharp/src/Google.Protobuf.Test/JsonParserTest.cs
+7
-0
JsonParser.cs
csharp/src/Google.Protobuf/JsonParser.cs
+15
-0
No files found.
csharp/src/Google.Protobuf.Test/JsonParserTest.cs
View file @
8866d6a8
...
...
@@ -895,6 +895,13 @@ namespace Google.Protobuf
Assert
.
Throws
<
InvalidProtocolBufferException
>(()
=>
TestAllTypes
.
Parser
.
ParseJson
(
json
));
}
[
Test
]
public
void
OneofDuplicate_Invalid
()
{
string
json
=
"{ \"oneofString\": \"x\", \"oneofUint32\": 10 }"
;
Assert
.
Throws
<
InvalidProtocolBufferException
>(()
=>
TestAllTypes
.
Parser
.
ParseJson
(
json
));
}
/// <summary>
/// Various tests use strings which have quotes round them for parsing or as the result
/// of formatting, but without those quotes being specified in the tests (for the sake of readability).
...
...
csharp/src/Google.Protobuf/JsonParser.cs
View file @
8866d6a8
...
...
@@ -168,6 +168,10 @@ namespace Google.Protobuf
}
var
descriptor
=
message
.
Descriptor
;
var
jsonFieldMap
=
descriptor
.
Fields
.
ByJsonName
();
// All the oneof fields we've already accounted for - we can only see each of them once.
// The set is created lazily to avoid the overhead of creating a set for every message
// we parsed, when oneofs are relatively rare.
HashSet
<
OneofDescriptor
>
seenOneofs
=
null
;
while
(
true
)
{
token
=
tokenizer
.
Next
();
...
...
@@ -183,6 +187,17 @@ namespace Google.Protobuf
FieldDescriptor
field
;
if
(
jsonFieldMap
.
TryGetValue
(
name
,
out
field
))
{
if
(
field
.
ContainingOneof
!=
null
)
{
if
(
seenOneofs
==
null
)
{
seenOneofs
=
new
HashSet
<
OneofDescriptor
>();
}
if
(!
seenOneofs
.
Add
(
field
.
ContainingOneof
))
{
throw
new
InvalidProtocolBufferException
(
$"Multiple values specified for oneof
{
field
.
ContainingOneof
.
Name
}
"
);
}
}
MergeField
(
message
,
field
,
tokenizer
);
}
else
...
...
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