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
d2d4b403
Unverified
Commit
d2d4b403
authored
Oct 12, 2018
by
Paul Yang
Committed by
GitHub
Oct 12, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sync upb for unknown fix (#5240)
parent
39df66e1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
0 deletions
+124
-0
upb.c
php/ext/google/protobuf/upb.c
+0
-0
encode_decode_test.php
php/tests/encode_decode_test.php
+124
-0
No files found.
php/ext/google/protobuf/upb.c
View file @
d2d4b403
This diff is collapsed.
Click to expand it.
php/tests/encode_decode_test.php
View file @
d2d4b403
...
...
@@ -23,6 +23,7 @@ use Google\Protobuf\BytesValue;
use
Google\Protobuf\Value
;
use
Google\Protobuf\ListValue
;
use
Google\Protobuf\Struct
;
use
Google\Protobuf\GPBEmpty
;
class
EncodeDecodeTest
extends
TestBase
{
...
...
@@ -660,6 +661,129 @@ class EncodeDecodeTest extends TestBase
$this
->
assertSame
(
"9a0400"
,
bin2hex
(
$to
));
}
public
function
testJsonUnknown
()
{
// Test unknown number
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":1,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown bool
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":true,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown string
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":
\"
abc
\"
,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown null
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":null,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown array
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":[],
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown number array
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":[1],
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown bool array
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":[true],
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown string array
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":[
\"
a
\"
],
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown null array
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":[null],
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown array array
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":[[]],
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown object array
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"
{
\"unknown\":[{
}
],
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown double value array
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":[1, 2],
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown object
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"
{
\"unknown\":{
}
,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown number object
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"
{
\"unknown\":{\"a\":1
}
,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown bool object
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"
{
\"unknown\":{\"a\":true
}
,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown string object
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"
{
\"unknown\":{\"a\":\"a\"
}
,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown null object
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"
{
\"unknown\":{\"a\":null
}
,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown array object
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"
{
\"unknown\":{\"a\":[]
}
,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown object object
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"
{
\"unknown\":{\"a\":{}
}
,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown double value object
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":{\"
a
\
":1,
\"
b
\"
:1},
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
}
public
function
testJsonEncode
()
{
$from
=
new
TestMessage
();
...
...
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