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
1e418e4e
Unverified
Commit
1e418e4e
authored
Dec 20, 2017
by
Adam Cozzette
Committed by
GitHub
Dec 20, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4068 from wsw2016/fix_4032
resolved issue 4032 and added a unit test
parents
860d693c
ac1fdd16
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
1 deletion
+27
-1
json_util.cc
src/google/protobuf/util/json_util.cc
+3
-1
json_util_test.cc
src/google/protobuf/util/json_util_test.cc
+24
-0
No files found.
src/google/protobuf/util/json_util.cc
View file @
1e418e4e
...
...
@@ -50,7 +50,9 @@ namespace util {
namespace
internal
{
ZeroCopyStreamByteSink
::~
ZeroCopyStreamByteSink
()
{
stream_
->
BackUp
(
buffer_size_
);
if
(
buffer_size_
>
0
)
{
stream_
->
BackUp
(
buffer_size_
);
}
}
void
ZeroCopyStreamByteSink
::
Append
(
const
char
*
bytes
,
size_t
len
)
{
...
...
src/google/protobuf/util/json_util_test.cc
View file @
1e418e4e
...
...
@@ -40,6 +40,7 @@
#include <google/protobuf/util/json_format_proto3.pb.h>
#include <google/protobuf/util/type_resolver.h>
#include <google/protobuf/util/type_resolver_util.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <gtest/gtest.h>
namespace
google
{
...
...
@@ -457,6 +458,29 @@ TEST(ZeroCopyStreamByteSinkTest, TestAllInputOutputPatterns) {
}
}
TEST_F
(
JsonUtilTest
,
TestWrongJsonInput
)
{
using
namespace
google
::
protobuf
;
const
char
json
[]
=
"{
\"
unknown_field
\"
:
\"
some_value
\"
}"
;
io
::
ArrayInputStream
input_stream
(
json
,
strlen
(
json
));
char
proto_buffer
[
10000
];
io
::
ArrayOutputStream
output_stream
(
proto_buffer
,
sizeof
(
proto_buffer
));
std
::
string
message_type
=
"type.googleapis.com/proto3.TestMessage"
;
TypeResolver
*
resolver
=
NewTypeResolverForDescriptorPool
(
"type.googleapis.com"
,
DescriptorPool
::
generated_pool
());
util
::
Status
result_status
=
util
::
JsonToBinaryStream
(
resolver
,
message_type
,
&
input_stream
,
&
output_stream
);
delete
resolver
;
EXPECT_FALSE
(
result_status
.
ok
());
EXPECT_EQ
(
result_status
.
error_code
(),
google
::
protobuf
::
util
::
error
::
INVALID_ARGUMENT
);
}
}
// namespace
}
// namespace util
}
// namespace protobuf
...
...
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