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
70544627
Commit
70544627
authored
6 years ago
by
Zachary Anker
Committed by
Paul Yang
6 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
When initializing a message, skip a field if value is nil (#3693)
parent
74f8e242
master
v3.11.4
v3.11.3
v3.11.2
v3.11.1
v3.11.0
v3.11.0-rc2
v3.11.0-rc1
v3.10.1
v3.10.0
v3.10.0-rc1
v3.9.2
v3.9.1
v3.9.0
v3.9.0-rc1
v3.8.0
v3.8.0-rc1
v3.7.1
v3.7.0
v3.7.0rc2
v3.7.0rc1
v3.7.0-rc.3
v3.7.0-rc.2
conformance-build-tag
No related merge requests found
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
0 deletions
+15
-0
message.c
ruby/ext/google/protobuf_c/message.c
+4
-0
RubyMessage.java
.../src/main/java/com/google/protobuf/jruby/RubyMessage.java
+2
-0
basic.rb
ruby/tests/basic.rb
+9
-0
No files found.
ruby/ext/google/protobuf_c/message.c
View file @
70544627
...
...
@@ -256,6 +256,10 @@ int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
"Unknown field name '%s' in initialization map entry."
,
name
);
}
if
(
TYPE
(
val
)
==
T_NIL
)
{
return
0
;
}
if
(
is_map_field
(
f
))
{
VALUE
map
;
...
...
This diff is collapsed.
Click to expand it.
ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java
View file @
70544627
...
...
@@ -86,6 +86,8 @@ public class RubyMessage extends RubyObject {
throw
runtime
.
newTypeError
(
"Expected string or symbols as hash keys in initialization map."
);
final
Descriptors
.
FieldDescriptor
fieldDescriptor
=
findField
(
context
,
key
);
if
(
value
.
isNil
())
return
;
if
(
Utils
.
isMapEntry
(
fieldDescriptor
))
{
if
(!(
value
instanceof
RubyHash
))
throw
runtime
.
newArgumentError
(
"Expected Hash object as initializer value for map field '"
+
key
.
asJavaString
()
+
"'."
);
...
...
This diff is collapsed.
Click to expand it.
ruby/tests/basic.rb
View file @
70544627
...
...
@@ -212,6 +212,15 @@ module BasicTest
assert_equal
[
'foo'
,
'bar'
],
m
.
repeated_string
end
def
test_ctor_nil_args
m
=
TestMessage
.
new
(
:optional_enum
=>
nil
,
:optional_int32
=>
nil
,
:optional_string
=>
nil
,
:optional_msg
=>
nil
)
assert_equal
:Default
,
m
.
optional_enum
assert_equal
0
,
m
.
optional_int32
assert_equal
""
,
m
.
optional_string
assert_nil
m
.
optional_msg
end
def
test_embeddedmsg_hash_init
m
=
TestEmbeddedMessageParent
.
new
(
:child_msg
=>
{
sub_child:
{
optional_int32:
1
}},
:number
=>
2
,
...
...
This diff is collapsed.
Click to expand it.
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