protobuf 2.4.3 → 2.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.3
4
+ version: 2.4.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -498,7 +498,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
498
498
  version: '0'
499
499
  segments:
500
500
  - 0
501
- hash: 1946796344651768063
501
+ hash: 1973744142414396176
502
502
  required_rubygems_version: !ruby/object:Gem::Requirement
503
503
  none: false
504
504
  requirements:
@@ -507,7 +507,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
507
507
  version: '0'
508
508
  segments:
509
509
  - 0
510
- hash: 1946796344651768063
510
+ hash: 1973744142414396176
511
511
  requirements: []
512
512
  rubyforge_project:
513
513
  rubygems_version: 1.8.24