protobuf 2.4.3-java → 2.4.4-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -175,7 +175,18 @@ module Protobuf
175
175
  @message_class.class_eval do
176
176
  define_method(field.setter_method_name) do |val|
177
177
  field.warn_if_deprecated
178
- val.compact! if val.respond_to?(:compact!)
178
+
179
+ if val.is_a?(Array)
180
+ val = val.dup
181
+ val.compact!
182
+ else
183
+ error_text = <<-TYPE_ERROR
184
+ Expected value of type '#{field.type}'
185
+ Got '#{val.class}' for protobuf field #{field.name}
186
+ TYPE_ERROR
187
+
188
+ raise TypeError, error_text
189
+ end
179
190
 
180
191
  if val.nil? || (val.respond_to?(:empty?) && val.empty?)
181
192
  @values.delete(field.name)
@@ -29,7 +29,7 @@ module Protobuf
29
29
 
30
30
  def replace(val)
31
31
  raise_type_error(val) unless val.is_a?(Array)
32
- val = val.map { |v| normalize(v) }
32
+ val = val.map! { |v| normalize(v) }
33
33
  super(val)
34
34
  end
35
35
 
@@ -52,6 +52,7 @@ module Protobuf
52
52
  #
53
53
  def normalize(value)
54
54
  raise TypeError unless @field.acceptable?(value)
55
+
55
56
  if @field.is_a?(::Protobuf::Field::EnumField)
56
57
  @field.type.fetch(value)
57
58
  elsif @field.is_a?(::Protobuf::Field::MessageField) && value.respond_to?(:to_hash)
@@ -1,4 +1,4 @@
1
1
  module Protobuf
2
- VERSION = '2.4.3'
2
+ VERSION = '2.4.4'
3
3
  PROTOC_VERSION = '2.4.1'
4
4
  end
@@ -46,6 +46,18 @@ describe Protobuf::Message do
46
46
  message.instance_variable_get("@values")[:repeated_enum].should be_nil
47
47
  end
48
48
 
49
+ it "does not compact the edit original array" do
50
+ a = [nil].freeze
51
+ message.repeated_enum = a
52
+ message.repeated_enum.should eq([])
53
+ a.should eq([nil].freeze)
54
+ end
55
+
56
+ it "compacts the set array" do
57
+ message.repeated_enum = [nil]
58
+ message.repeated_enum.should eq([])
59
+ end
60
+
49
61
  it "raises TypeError when a non-array replaces it" do
50
62
  expect {
51
63
  message.repeated_enum = 2
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: protobuf
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.4.3
5
+ version: 2.4.4
6
6
  platform: java
7
7
  authors:
8
8
  - BJ Neilsen