bson 4.9.5-java → 4.12.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 076c6afb241755ea9ecabc3851bf2a63e1e468218e1cabf47bfea79cbc666c8d
4
- data.tar.gz: 9410f895fbbee05b6c0fa1bd985ec40da927800cfae994319508bbaca62ae95a
3
+ metadata.gz: fdf6c4e223ffb2096c37888da541dfc5c1d93d0776f13411f48c1a5db88ccf20
4
+ data.tar.gz: b2451c9140eaf9c2357db2f90c0890c3e81fe27dbe490d8c6e600f2c4926a779
5
5
  SHA512:
6
- metadata.gz: d148ccfdbc61664f314735748a370627835558382a29e1bebc3ace59c75488e5f6d9351b74e75fff8f8ad4d2bbbb1f47f9dbfae7133abdc8bb66cadc86b1c043
7
- data.tar.gz: 0cce82125862e31e0020bd83a99d33548b9a41768148171c88daf384047c7eaf7c99588a7e71319ceeb8649b7b0dadca460370d25e7ea6bb29b99abaeb0223d8
6
+ metadata.gz: 16975daf3fa38ac33ab59cd9f19f9a4f5115bc1d7ee23170a8ba1ec3837352220d90e5f8352fb4df83b85d4258e9996bdb80e6b02276b93c1d455e77004b410a
7
+ data.tar.gz: 91e3c157d966a356e52680ae3ff9bdf9df027bff02c59a44129b43c9359c220a0747b984316690d4fb3a2add8e54412bc90781e6eebd249f7dd48b757575ae90
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/bson-ruby.jar CHANGED
Binary file
data/lib/bson/binary.rb CHANGED
@@ -207,7 +207,8 @@ module BSON
207
207
  if representation && representation != :standard
208
208
  raise ArgumentError, "Binary of type :uuid can only be stringified to :standard representation, requested: #{representation.inspect}"
209
209
  end
210
- data.split('').map { |n| '%02x' % n.ord }.join.sub(/(.{8})(.{4})(.{4})(.{12})/, '\1-\2-\3-\4')
210
+
211
+ data.split('').map { |n| '%02x' % n.ord }.join.sub(/\A(.{8})(.{4})(.{4})(.{4})(.{12})\z/, '\1-\2-\3-\4-\5')
211
212
  when :uuid_old
212
213
  if representation.nil?
213
214
  raise ArgumentError, 'Representation must be specified for BSON::Binary objects of type :uuid_old'
@@ -229,7 +230,7 @@ module BSON
229
230
  hex
230
231
  else
231
232
  raise ArgumentError, "Invalid representation: #{representation}"
232
- end.sub(/(.{8})(.{4})(.{4})(.{12})/, '\1-\2-\3-\4')
233
+ end.sub(/\A(.{8})(.{4})(.{4})(.{4})(.{12})\z/, '\1-\2-\3-\4-\5')
233
234
  else
234
235
  raise TypeError, "The type of Binary must be :uuid or :uuid_old, this object is: #{type.inspect}"
235
236
  end
@@ -35,7 +35,7 @@ module BSON
35
35
  #
36
36
  # @since 2.1.0
37
37
  def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
38
- to_time.to_bson(buffer)
38
+ gregorian.to_time.to_bson(buffer)
39
39
  end
40
40
  end
41
41
 
data/lib/bson/document.rb CHANGED
@@ -269,27 +269,52 @@ module BSON
269
269
  end
270
270
  end
271
271
 
272
- if instance_methods.include?(:slice)
273
- # Slices a document to include only the given keys.
274
- # Will normalize symbol keys into strings.
275
- # (this method is backported from ActiveSupport::Hash)
276
- #
277
- # @example Get a document/hash with only the `name` and `age` fields present
278
- # document # => { _id: <ObjectId>, :name => 'John', :age => 30, :location => 'Earth' }
279
- # document.slice(:name, 'age') # => { name: 'John', age: 30 }
280
- # document.slice('name') # => { name: 'John' }
281
- # document.slice(:foo) # => nil
282
- #
283
- # @param [ Array<String, Symbol> ] *keys Keys, that will be kept in the resulting document
284
- #
285
- # @return [ BSON::Document ] The document with only the selected keys
286
- #
287
- # @since 4.3.1
288
- def slice(*keys)
289
- super(*keys.map{|key| convert_key(key)})
272
+ # Slices a document to include only the given keys.
273
+ # Will normalize symbol keys into strings.
274
+ # (this method is backported from ActiveSupport::Hash)
275
+ #
276
+ # @example Get a document/hash with only the `name` and `age` fields present
277
+ # document # => { _id: <ObjectId>, :name => "John", :age => 30, :location => "Earth" }
278
+ # document.slice(:name, 'age') # => { "name": "John", "age" => 30 }
279
+ # document.slice('name') # => { "name" => "John" }
280
+ # document.slice(:foo) # => {}
281
+ #
282
+ # @param [ Array<String, Symbol> ] *keys Keys, that will be kept in the resulting document
283
+ #
284
+ # @return [ BSON::Document ] The document with only the selected keys
285
+ #
286
+ # @since 4.3.1
287
+ def slice(*keys)
288
+ keys.each_with_object(self.class.new) do |key, hash|
289
+ if key?(key)
290
+ hash[key] = self[key]
291
+ end
290
292
  end
291
293
  end
292
294
 
295
+ # Returns a new document consisting of the current document minus the
296
+ # specified keys.
297
+ #
298
+ # The keys to be removed can be specified as either strings or symbols.
299
+ #
300
+ # @example Get a document/hash with only the `name` and `age` fields removed
301
+ # document # => { _id: <ObjectId>, :name => 'John', :age => 30, :location => 'Earth' }
302
+ # document.except(:name, 'age') # => { _id: <ObjectId>, location: 'Earth' }
303
+ #
304
+ # @param [ Array<String, Symbol> ] *keys Keys, that will be removed in the resulting document
305
+ #
306
+ # @return [ BSON::Document ] The document with the specified keys removed.
307
+ #
308
+ # @note This method is always defined, even if Hash already contains a
309
+ # definition of #except, because ActiveSupport unconditionally defines
310
+ # its version of #except which doesn't work for BSON::Document which
311
+ # causes problems if ActiveSupport is loaded after bson-ruby is.
312
+ def except(*keys)
313
+ copy = dup
314
+ keys.each {|key| copy.delete(key)}
315
+ copy
316
+ end
317
+
293
318
  private
294
319
 
295
320
  def convert_key(key)
data/lib/bson/ext_json.rb CHANGED
@@ -219,6 +219,14 @@ module BSON
219
219
  raise Error::ExtJSONParseError, "Invalid subType value in $binary: #{value}"
220
220
  end
221
221
  create_binary(encoded_value, subtype)
222
+
223
+ when '$uuid'
224
+ unless /\A[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\z/.match(value)
225
+ raise Error::ExtJSONParseError, "Invalid $uuid value: #{value}"
226
+ end
227
+
228
+ return Binary.from_uuid(value)
229
+
222
230
  when '$code'
223
231
  unless value.is_a?(String)
224
232
  raise Error::ExtJSONParseError, "Invalid $code value: #{value}"
@@ -124,8 +124,8 @@ module BSON
124
124
  #
125
125
  # @since 2.0.0
126
126
  def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
127
- buffer.put_int32(increment)
128
- buffer.put_int32(seconds)
127
+ buffer.put_uint32(increment)
128
+ buffer.put_uint32(seconds)
129
129
  end
130
130
 
131
131
  # Deserialize timestamp from BSON.
@@ -140,8 +140,8 @@ module BSON
140
140
  #
141
141
  # @since 2.0.0
142
142
  def self.from_bson(buffer, **options)
143
- increment = buffer.get_int32
144
- seconds = buffer.get_int32
143
+ increment = buffer.get_uint32
144
+ seconds = buffer.get_uint32
145
145
  new(seconds, increment)
146
146
  end
147
147
 
data/lib/bson/version.rb CHANGED
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module BSON
16
- VERSION = "4.9.5".freeze
16
+ VERSION = "4.12.0".freeze
17
17
  end
@@ -255,7 +255,7 @@ describe BSON::Binary do
255
255
  let(:obj) { described_class.new("\x00" * 16, :uuid) }
256
256
 
257
257
  it 'accepts symbol representation' do
258
- expect(obj.to_uuid(:standard)).to eq('00000000-0000-0000-0000000000000000')
258
+ expect(obj.to_uuid(:standard)).to eq('00000000-0000-0000-0000-000000000000')
259
259
  end
260
260
 
261
261
  it 'rejects string representation' do
@@ -136,6 +136,10 @@ describe "BSON::Binary - UUID spec tests" do
136
136
  it 'decodes as python legacy' do
137
137
  expect(binary.to_uuid(:python_legacy).gsub('-', '').upcase).not_to eq("00112233445566778899AABBCCDDEEFF")
138
138
  end
139
+
140
+ it 'expects four dashes when output as String' do
141
+ expect(binary.to_uuid(:csharp_legacy)).to eq("00112233-4455-6677-8899-aabbccddeeff")
142
+ end
139
143
  end
140
144
 
141
145
  context ':uuid_old, java legacy encoded' do
@@ -154,6 +158,10 @@ describe "BSON::Binary - UUID spec tests" do
154
158
  it 'decodes as python legacy' do
155
159
  expect(binary.to_uuid(:python_legacy).gsub('-', '').upcase).not_to eq("00112233445566778899AABBCCDDEEFF")
156
160
  end
161
+
162
+ it 'expects four dashes when output as String' do
163
+ expect(binary.to_uuid(:java_legacy)).to eq("00112233-4455-6677-8899-aabbccddeeff")
164
+ end
157
165
  end
158
166
 
159
167
  context ':uuid_old, python legacy encoded' do
@@ -172,6 +180,10 @@ describe "BSON::Binary - UUID spec tests" do
172
180
  it 'decodes as python legacy' do
173
181
  expect(binary.to_uuid(:python_legacy).gsub('-', '').upcase).to eq("00112233445566778899AABBCCDDEEFF")
174
182
  end
183
+
184
+ it 'expects four dashes when output as String' do
185
+ expect(binary.to_uuid(:python_legacy)).to eq("00112233-4455-6677-8899-aabbccddeeff")
186
+ end
175
187
  end
176
188
  end
177
189
  end
@@ -66,7 +66,7 @@ describe BSON::ByteBuffer do
66
66
  describe '#get_double' do
67
67
 
68
68
  let(:buffer) do
69
- described_class.new("#{12.5.to_bson.to_s}")
69
+ described_class.new(12.5.to_bson.to_s)
70
70
  end
71
71
 
72
72
  let!(:double) do
@@ -85,7 +85,7 @@ describe BSON::ByteBuffer do
85
85
  describe '#get_int32' do
86
86
 
87
87
  let(:buffer) do
88
- described_class.new("#{12.to_bson.to_s}")
88
+ described_class.new(12.to_bson.to_s)
89
89
  end
90
90
 
91
91
  let!(:int32) do
@@ -101,10 +101,66 @@ describe BSON::ByteBuffer do
101
101
  end
102
102
  end
103
103
 
104
+ describe '#get_uint32' do
105
+ context 'when using 2^32-1' do
106
+ let(:buffer) do
107
+ described_class.new(4294967295.to_bson.to_s)
108
+ end
109
+
110
+ let!(:int32) do
111
+ buffer.get_uint32
112
+ end
113
+
114
+ it 'gets the uint32 from the buffer' do
115
+ expect(int32).to eq(4294967295)
116
+ end
117
+
118
+ it 'increments the position by 4' do
119
+ expect(buffer.read_position).to eq(4)
120
+ end
121
+ end
122
+
123
+ context 'when using 2^32-2' do
124
+ let(:buffer) do
125
+ described_class.new(4294967294.to_bson.to_s)
126
+ end
127
+
128
+ let!(:int32) do
129
+ buffer.get_uint32
130
+ end
131
+
132
+ it 'gets the uint32 from the buffer' do
133
+ expect(int32).to eq(4294967294)
134
+ end
135
+
136
+ it 'increments the position by 4' do
137
+ expect(buffer.read_position).to eq(4)
138
+ end
139
+ end
140
+
141
+ context 'when using 0' do
142
+ let(:buffer) do
143
+ described_class.new(0.to_bson.to_s)
144
+ end
145
+
146
+ let!(:int32) do
147
+ buffer.get_uint32
148
+ end
149
+
150
+ it 'gets the uint32 from the buffer' do
151
+ expect(int32).to eq(0)
152
+ end
153
+
154
+ it 'increments the position by 4' do
155
+ expect(buffer.read_position).to eq(4)
156
+ end
157
+ end
158
+ end
159
+
104
160
  describe '#get_int64' do
105
161
 
106
162
  let(:buffer) do
107
- described_class.new("#{(Integer::MAX_64BIT - 1).to_bson.to_s}")
163
+ described_class.new((Integer::MAX_64BIT - 1).to_bson.to_s)
108
164
  end
109
165
 
110
166
  let!(:int64) do
@@ -31,12 +31,14 @@ describe BSON::ByteBuffer do
31
31
  described_class.new
32
32
  end
33
33
 
34
- before do
35
- buffer.put_int32(5)
36
- end
37
-
38
- it 'returns the length of the buffer' do
39
- expect(buffer.length).to eq(4)
34
+ context '#put_int32' do
35
+ before do
36
+ buffer.put_int32(5)
37
+ end
38
+
39
+ it 'returns the length of the buffer' do
40
+ expect(buffer.length).to eq(4)
41
+ end
40
42
  end
41
43
  end
42
44
 
@@ -50,6 +52,50 @@ describe BSON::ByteBuffer do
50
52
  expect(buffer.length).to eq(2)
51
53
  end
52
54
  end
55
+
56
+ context 'after the byte buffer was read from' do
57
+
58
+ let(:buffer) do
59
+ described_class.new({}.to_bson.to_s)
60
+ end
61
+
62
+ it 'returns the number of bytes remaining in the buffer' do
63
+ expect(buffer.length).to eq(5)
64
+ buffer.get_int32
65
+ expect(buffer.length).to eq(1)
66
+ end
67
+ end
68
+
69
+ context 'after the byte buffer was converted to string' do
70
+
71
+ shared_examples 'returns the total buffer length' do
72
+ it 'returns the total buffer length' do
73
+ expect(buffer.length).to eq(5)
74
+ buffer.to_s.length.should == 5
75
+ expect(buffer.length).to eq(5)
76
+ end
77
+ end
78
+
79
+ context 'read buffer' do
80
+
81
+ let(:buffer) do
82
+ described_class.new({}.to_bson.to_s)
83
+ end
84
+
85
+ include_examples 'returns the total buffer length'
86
+ end
87
+
88
+ context 'write buffer' do
89
+
90
+ let(:buffer) do
91
+ described_class.new.tap do |buffer|
92
+ buffer.put_bytes('hello')
93
+ end
94
+ end
95
+
96
+ include_examples 'returns the total buffer length'
97
+ end
98
+ end
53
99
  end
54
100
 
55
101
  describe '#rewind!' do
@@ -104,4 +150,81 @@ describe BSON::ByteBuffer do
104
150
  expect(buffer.write_position).to eq(1)
105
151
  end
106
152
  end
153
+
154
+ describe 'write followed by read' do
155
+ let(:buffer) do
156
+ described_class.new
157
+ end
158
+
159
+ context 'one cycle' do
160
+ it 'returns the written data' do
161
+ buffer.put_cstring('hello')
162
+ buffer.get_cstring.should == 'hello'
163
+ end
164
+ end
165
+
166
+ context 'two cycles' do
167
+ it 'returns the written data' do
168
+ buffer.put_cstring('hello')
169
+ buffer.get_cstring.should == 'hello'
170
+
171
+ buffer.put_cstring('world')
172
+ buffer.get_cstring.should == 'world'
173
+ end
174
+ end
175
+
176
+ context 'mixed cycles' do
177
+ it 'returns the written data' do
178
+ if BSON::Environment.jruby?
179
+ pending 'RUBY-2334'
180
+ end
181
+
182
+ buffer.put_int32(1)
183
+ buffer.put_int32(2)
184
+
185
+ buffer.get_int32.should == 1
186
+
187
+ buffer.put_int32(3)
188
+
189
+ buffer.get_int32.should == 2
190
+ buffer.get_int32.should == 3
191
+ end
192
+ end
193
+ end
194
+
195
+ describe '#to_s' do
196
+ context 'read buffer' do
197
+ let(:buffer) do
198
+ described_class.new("\x18\x00\x00\x00*\x00\x00\x00")
199
+ end
200
+
201
+ it 'returns the data' do
202
+ buffer.to_s.should == "\x18\x00\x00\x00*\x00\x00\x00"
203
+ end
204
+
205
+ it 'returns the remaining buffer contents after a read' do
206
+ buffer.to_s.should == "\x18\x00\x00\x00*\x00\x00\x00"
207
+ buffer.get_int32.should == 24
208
+ buffer.to_s.should == "*\x00\x00\x00"
209
+ end
210
+ end
211
+
212
+ context 'write buffer' do
213
+ let(:buffer) do
214
+ described_class.new.tap do |buffer|
215
+ buffer.put_int32(24)
216
+ end
217
+ end
218
+
219
+ it 'returns the data' do
220
+ buffer.to_s.should == "\x18\x00\x00\x00".force_encoding('binary')
221
+ end
222
+
223
+ it 'returns the complete buffer contents after a write' do
224
+ buffer.to_s.should == "\x18\x00\x00\x00".force_encoding('binary')
225
+ buffer.put_int32(42)
226
+ buffer.to_s.should == "\x18\x00\x00\x00*\x00\x00\x00".force_encoding('binary')
227
+ end
228
+ end
229
+ end
107
230
  end
@@ -585,6 +585,102 @@ describe BSON::ByteBuffer do
585
585
  end
586
586
  end
587
587
 
588
+ describe '#put_uint32' do
589
+ context 'when argument is a float' do
590
+ it 'raises an Argument Error' do
591
+ expect{ buffer.put_uint32(4.934) }.to raise_error(ArgumentError, "put_uint32: incorrect type: float, expected: integer")
592
+ end
593
+ end
594
+
595
+ context 'when number is in range' do
596
+ let(:modified) do
597
+ buffer.put_uint32(5)
598
+ end
599
+
600
+ it 'returns gets the correct number from the buffer' do
601
+ expect(modified.get_uint32).to eq(5)
602
+ end
603
+
604
+ it 'returns the length of the buffer' do
605
+ expect(modified.length).to eq(4)
606
+ end
607
+ end
608
+
609
+ context 'when number is 0' do
610
+ let(:modified) do
611
+ buffer.put_uint32(0)
612
+ end
613
+
614
+ it 'returns gets the correct number from the buffer' do
615
+ expect(modified.get_uint32).to eq(0)
616
+ end
617
+
618
+ it 'returns the length of the buffer' do
619
+ expect(modified.length).to eq(4)
620
+ end
621
+ end
622
+
623
+ context 'when number doesn\'t fit in signed int32' do
624
+ let(:modified) do
625
+ buffer.put_uint32(4294967295)
626
+ end
627
+
628
+ let(:expected) do
629
+ [ 4294967295 ].pack(BSON::Int32::PACK)
630
+ end
631
+
632
+ it 'appends the int32 to the byte buffer' do
633
+ expect(modified.to_s).to eq(expected)
634
+ end
635
+
636
+ it 'get returns correct number' do
637
+ expect(modified.get_uint32).to eq(4294967295)
638
+ end
639
+
640
+ it 'returns the length of the buffer' do
641
+ expect(modified.length).to eq(4)
642
+ end
643
+ end
644
+
645
+ context 'when number is 2^31' do
646
+ let(:modified) do
647
+ buffer.put_uint32(2147483648)
648
+ end
649
+
650
+ it 'returns gets the correct number from the buffer' do
651
+ expect(modified.get_uint32).to eq(2147483648)
652
+ end
653
+
654
+ it 'returns the length of the buffer' do
655
+ expect(modified.length).to eq(4)
656
+ end
657
+ end
658
+
659
+ context 'when number is 2^31-1' do
660
+ let(:modified) do
661
+ buffer.put_uint32(2147483647)
662
+ end
663
+
664
+ it 'returns gets the correct number from the buffer' do
665
+ expect(modified.get_uint32).to eq(2147483647)
666
+ end
667
+
668
+ it 'returns the length of the buffer' do
669
+ expect(modified.length).to eq(4)
670
+ end
671
+ end
672
+
673
+ context 'when number is not in range' do
674
+ it 'raises error on out of top range' do
675
+ expect{ buffer.put_uint32(4294967296) }.to raise_error(RangeError, "Number 4294967296 is out of range [0, 2^32)")
676
+ end
677
+
678
+ it 'raises error on out of bottom range' do
679
+ expect{ buffer.put_uint32(-1) }.to raise_error(RangeError, "Number -1 is out of range [0, 2^32)")
680
+ end
681
+ end
682
+ end
683
+
588
684
  describe '#put_int64' do
589
685
 
590
686
  context 'when the integer is 64 bit' do
@@ -35,5 +35,58 @@ describe DateTime do
35
35
 
36
36
  it_behaves_like "a serializable bson element"
37
37
  end
38
+
39
+ context "when the dates don't both use Gregorian" do
40
+
41
+ let(:shakespeare_datetime) do
42
+ DateTime.iso8601('1616-04-23', Date::ENGLAND)
43
+ end
44
+
45
+ let(:gregorian_datetime) do
46
+ DateTime.iso8601('1616-04-23', Date::GREGORIAN)
47
+ end
48
+
49
+ context "when putting to bson" do
50
+
51
+ let(:shakespeare) do
52
+ { a: shakespeare_datetime }.to_bson
53
+ end
54
+
55
+ let(:gregorian) do
56
+ { a: gregorian_datetime }.to_bson
57
+ end
58
+
59
+ it "does not equal each other" do
60
+ expect(shakespeare.to_s).to_not eq(gregorian.to_s)
61
+ end
62
+
63
+ it "the english date is 10 days later" do
64
+ expect(shakespeare.to_s).to eq({ a: DateTime.iso8601('1616-05-03', Date::GREGORIAN) }.to_bson.to_s)
65
+ end
66
+ end
67
+
68
+ context "when putting and receiving from bson" do
69
+
70
+ let(:shakespeare) do
71
+ Hash.from_bson(BSON::ByteBuffer.new({ a: shakespeare_datetime }.to_bson.to_s))
72
+ end
73
+
74
+ let(:gregorian) do
75
+ Hash.from_bson(BSON::ByteBuffer.new({ a: gregorian_datetime }.to_bson.to_s))
76
+ end
77
+
78
+ it "does not equal each other" do
79
+ expect(shakespeare).to_not eq(gregorian)
80
+ end
81
+
82
+ it "the english date is 10 days later" do
83
+ expect(shakespeare[:a]).to eq(DateTime.iso8601('1616-05-03', Date::GREGORIAN).to_time)
84
+ end
85
+
86
+ it "the gregorian date is the same" do
87
+ expect(gregorian[:a]).to eq(DateTime.iso8601('1616-04-23', Date::GREGORIAN).to_time)
88
+ end
89
+ end
90
+ end
38
91
  end
39
92
  end
@@ -215,6 +215,10 @@ describe BSON::Document do
215
215
 
216
216
  context "when provided string keys" do
217
217
 
218
+ it "is a BSON Document" do
219
+ expect(document.slice("key1")).to be_a(BSON::Document)
220
+ end
221
+
218
222
  it "returns the partial document" do
219
223
  expect(document.slice("key1")).to contain_exactly(['key1', 'value1'])
220
224
  end
@@ -222,13 +226,45 @@ describe BSON::Document do
222
226
 
223
227
  context "when provided symbol keys" do
224
228
 
229
+ it "is a BSON Document" do
230
+ expect(document.slice(:key1)).to be_a(BSON::Document)
231
+ end
232
+
225
233
  it "returns the partial document" do
226
234
  expect(document.slice(:key1)).to contain_exactly(['key1', 'value1'])
227
235
  end
228
236
  end
237
+
238
+ context "when provided keys that do not exist in the document" do
239
+
240
+ it "returns only the keys that exist in the document" do
241
+ expect(document.slice(:key1, :key3)).to contain_exactly(['key1', 'value1'])
242
+ end
243
+ end
229
244
  end
230
245
  end
231
246
 
247
+ describe "#except" do
248
+ let(:document) do
249
+ described_class.new("key1" => "value1", key2: "value2")
250
+ end
251
+
252
+ context "when provided string keys" do
253
+
254
+ it "returns the partial document" do
255
+ expect(document.except("key1")).to contain_exactly(['key2', 'value2'])
256
+ end
257
+ end
258
+
259
+ context "when provided symbol keys" do
260
+
261
+ it "returns the partial document" do
262
+ expect(document.except(:key1)).to contain_exactly(['key2', 'value2'])
263
+ end
264
+ end
265
+ end
266
+
267
+
232
268
  describe "#delete" do
233
269
 
234
270
  shared_examples_for "a document with deletable pairs" do
@@ -244,6 +244,16 @@ describe Hash do
244
244
  /(Hash value for key 'foo'|Value) does not define its BSON serialized type:.*HashSpecUnserializableClass/)
245
245
  end
246
246
  end
247
+
248
+ context 'when reading from a byte buffer that was previously written to' do
249
+ let(:buffer) do
250
+ {foo: 42}.to_bson
251
+ end
252
+
253
+ it 'returns the original hash' do
254
+ expect(Hash.from_bson(buffer)).to eq('foo' => 42)
255
+ end
256
+ end
247
257
  end
248
258
 
249
259
  describe '#to_bson' do
@@ -310,4 +320,50 @@ describe Hash do
310
320
  end
311
321
  end
312
322
  end
323
+
324
+ describe '#from_bson' do
325
+ context 'when bson document has duplicate keys' do
326
+ let(:buf) do
327
+ buf = BSON::ByteBuffer.new
328
+ buf.put_int32(37)
329
+ buf.put_byte("\x02")
330
+ buf.put_cstring('foo')
331
+ buf.put_string('bar')
332
+ buf.put_byte("\x02")
333
+ buf.put_cstring('foo')
334
+ buf.put_string('overwrite')
335
+ buf.put_byte("\x00")
336
+
337
+ BSON::ByteBuffer.new(buf.to_s)
338
+ end
339
+
340
+ let(:doc) { Hash.from_bson(buf) }
341
+
342
+ it 'overwrites first value with second value' do
343
+ doc.should == {'foo' => 'overwrite'}
344
+ end
345
+ end
346
+
347
+ context 'when bson document has string and symbol keys of the same name' do
348
+ let(:buf) do
349
+ buf = BSON::ByteBuffer.new
350
+ buf.put_int32(31)
351
+ buf.put_byte("\x02")
352
+ buf.put_cstring('foo')
353
+ buf.put_string('bar')
354
+ buf.put_byte("\x0e")
355
+ buf.put_cstring('foo')
356
+ buf.put_string('bar')
357
+ buf.put_byte("\x00")
358
+
359
+ BSON::ByteBuffer.new(buf.to_s)
360
+ end
361
+
362
+ let(:doc) { Hash.from_bson(buf) }
363
+
364
+ it 'overwrites first value with second value' do
365
+ doc.should == {'foo' => :bar}
366
+ end
367
+ end
368
+ end
313
369
  end
@@ -39,6 +39,12 @@
39
39
  "canonical_bson": "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400",
40
40
  "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"04\"}}}"
41
41
  },
42
+ {
43
+ "description": "subtype 0x04 UUID",
44
+ "canonical_bson": "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400",
45
+ "canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"04\"}}}",
46
+ "degenerate_extjson": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4\"}}"
47
+ },
42
48
  {
43
49
  "description": "subtype 0x05",
44
50
  "canonical_bson": "1D000000057800100000000573FFD26444B34C6990E8E7D1DFC035D400",
@@ -81,5 +87,15 @@
81
87
  "description": "subtype 0x02 length negative one",
82
88
  "bson": "130000000578000600000002FFFFFFFFFFFF00"
83
89
  }
90
+ ],
91
+ "parseErrors": [
92
+ {
93
+ "description": "$uuid wrong type",
94
+ "string": "{\"x\" : { \"$uuid\" : { \"data\" : \"73ffd264-44b3-4c69-90e8-e7d1dfc035d4\"}}}"
95
+ },
96
+ {
97
+ "description": "$uuid invalid value",
98
+ "string": "{\"x\" : { \"$uuid\" : \"73ffd264-44b3-90e8-e7d1dfc035d4\"}}"
99
+ }
84
100
  ]
85
101
  }
@@ -13,6 +13,16 @@
13
13
  "canonical_bson": "100000001161002A00000015CD5B0700",
14
14
  "canonical_extjson": "{\"a\" : {\"$timestamp\" : {\"t\" : 123456789, \"i\" : 42} } }",
15
15
  "degenerate_extjson": "{\"a\" : {\"$timestamp\" : {\"i\" : 42, \"t\" : 123456789} } }"
16
+ },
17
+ {
18
+ "description": "Timestamp with high-order bit set on both seconds and increment",
19
+ "canonical_bson": "10000000116100FFFFFFFFFFFFFFFF00",
20
+ "canonical_extjson": "{\"a\" : {\"$timestamp\" : {\"t\" : 4294967295, \"i\" : 4294967295} } }"
21
+ },
22
+ {
23
+ "description": "Timestamp with high-order bit set on both seconds and increment (not UINT32_MAX)",
24
+ "canonical_bson": "1000000011610000286BEE00286BEE00",
25
+ "canonical_extjson": "{\"a\" : {\"$timestamp\" : {\"t\" : 4000000000, \"i\" : 4000000000} } }"
16
26
  }
17
27
  ],
18
28
  "decodeErrors": [
@@ -65,11 +65,11 @@
65
65
  "parseErrors": [
66
66
  {
67
67
  "description" : "Bad $regularExpression (extra field)",
68
- "string" : "{\"a\" : \"$regularExpression\": {\"pattern\": \"abc\", \"options\": \"\", \"unrelated\": true}}}"
68
+ "string" : "{\"a\" : {\"$regularExpression\": {\"pattern\": \"abc\", \"options\": \"\", \"unrelated\": true}}}"
69
69
  },
70
70
  {
71
71
  "description" : "Bad $regularExpression (missing options field)",
72
- "string" : "{\"a\" : \"$regularExpression\": {\"pattern\": \"abc\"}}}"
72
+ "string" : "{\"a\" : {\"$regularExpression\": {\"pattern\": \"abc\"}}}"
73
73
  },
74
74
  {
75
75
  "description": "Bad $regularExpression (pattern is number, not string)",
@@ -81,7 +81,7 @@
81
81
  },
82
82
  {
83
83
  "description" : "Bad $regularExpression (missing pattern field)",
84
- "string" : "{\"a\" : \"$regularExpression\": {\"options\":\"ix\"}}}"
84
+ "string" : "{\"a\" : {\"$regularExpression\": {\"options\":\"ix\"}}}"
85
85
  },
86
86
  {
87
87
  "description": "Bad $oid (number, not string)",
@@ -6,7 +6,8 @@ class SpecConfig
6
6
  COMPACTION_CHANCE = 0.001
7
7
 
8
8
  def active_support?
9
- %w(1 true yes).include?(ENV['WITH_ACTIVE_SUPPORT'])
9
+ %w(1 true yes).include?(ENV['WITH_ACTIVE_SUPPORT']) ||
10
+ ENV['WITH_ACTIVE_SUPPORT'] =~ /[0-9]/ && ENV['WITH_ACTIVE_SUPPORT'] != '0'
10
11
  end
11
12
 
12
13
  def compact?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bson
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.9.5
4
+ version: 4.12.0
5
5
  platform: java
6
6
  authors:
7
7
  - Tyler Brock
@@ -15,8 +15,8 @@ cert_chain:
15
15
  - |
16
16
  -----BEGIN CERTIFICATE-----
17
17
  MIIDRDCCAiygAwIBAgIBATANBgkqhkiG9w0BAQsFADAmMSQwIgYDVQQDDBtkcml2
18
- ZXItcnVieS9EQz0xMGdlbi9EQz1jb20wHhcNMjAwMTIzMTkzNjAxWhcNMjEwMTIy
19
- MTkzNjAxWjAmMSQwIgYDVQQDDBtkcml2ZXItcnVieS9EQz0xMGdlbi9EQz1jb20w
18
+ ZXItcnVieS9EQz0xMGdlbi9EQz1jb20wHhcNMjEwMjA5MTQxOTU3WhcNMjIwMjA5
19
+ MTQxOTU3WjAmMSQwIgYDVQQDDBtkcml2ZXItcnVieS9EQz0xMGdlbi9EQz1jb20w
20
20
  ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDRXUgGvH0ZtWwDPc2umdHw
21
21
  B+INNm6jNTRp8PMyUKxPzxaxX2OiBQk9gLC3zsK9ZmlZu4lNfpHVSCEPoiP/fhPg
22
22
  Kyfq2xld3Qz0Pki5d5i0/r14343MTKiNiFulLlbbdlN0cXeEFNJHUycZnD2LOXwz
@@ -26,14 +26,14 @@ cert_chain:
26
26
  AgMBAAGjfTB7MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBRbd1mx
27
27
  fvSaVIwKI+tnEAYDW/B81zAgBgNVHREEGTAXgRVkcml2ZXItcnVieUAxMGdlbi5j
28
28
  b20wIAYDVR0SBBkwF4EVZHJpdmVyLXJ1YnlAMTBnZW4uY29tMA0GCSqGSIb3DQEB
29
- CwUAA4IBAQBfX4dwxG5PhtxES/LDEOaZIZXyaX6CKe367zhW+HxWbSOXMQJFkIQj
30
- m7tzT+sDFJXyiOv5cPtfpUam5pTiryzRw5HD6oxlPIt5vO15EJ69v++3m7shMLbw
31
- amZOajKXmu2ZGZfhOtj7bOTwmOj1AnWLKeOQIR3STvvfZCD+6dt1XenW7CdjCsxE
32
- ifervPjLFqFPsMOgaxikhgPK6bRtszrQhJSYlifKKzxbX1hYAsmGL7IxjubFSV5r
33
- gpvfPNWMwyBDlHaNS3GfO6cRRxBOvEG05GUCsvtTY4Bpe8yjE64wg1ymb47LMOnv
34
- Qb1lGORmf/opg45mluKUYl7pQNZHD0d3
29
+ CwUAA4IBAQCYGRgQbtk+g+Nuwg15p8jb+8bJlwHFHkb8rkLn00OPXLk3uBhImOKZ
30
+ mhwwr/8ZBkeE/PBDxkQjeua+NpqSaPr1lvXQaGpHxJzpR/BmSteeoF49jBu0dHaz
31
+ MRghinst6ROS1qVRae0z+wkbnufpH/NxdCUufb639nAlZguT2rGqvM6VZCC8eSO9
32
+ KfJA7/MEE+qQtiQgJaAUVRaGC8fLtmS555BPjNVITJs+BcGDYWh2clWuqlzjHOp3
33
+ YoFhlyUEi7VLlqNH0H/JFttVZK6+qmLelkVNcIYVLeWOB4Lf4VxEiYGEK1ORxsrY
34
+ iyYKJJALWY1FAInGRIlvkN+B8o3yIhq1
35
35
  -----END CERTIFICATE-----
36
- date: 2020-10-13 00:00:00.000000000 Z
36
+ date: 2021-02-09 00:00:00.000000000 Z
37
37
  dependencies: []
38
38
  description: A fully featured BSON specification implementation in Ruby
39
39
  email:
@@ -89,7 +89,6 @@ files:
89
89
  - lib/bson/true_class.rb
90
90
  - lib/bson/undefined.rb
91
91
  - lib/bson/version.rb
92
- - lib/bson_native.bundle
93
92
  - spec/bson/array_spec.rb
94
93
  - spec/bson/binary_spec.rb
95
94
  - spec/bson/binary_uuid_spec.rb
@@ -231,111 +230,111 @@ summary: Ruby implementation of the BSON specification
231
230
  test_files:
232
231
  - spec/spec_helper.rb
233
232
  - spec/bson_spec.rb
233
+ - spec/spec_tests/corpus_spec.rb
234
234
  - spec/spec_tests/common_driver_spec.rb
235
235
  - spec/spec_tests/corpus_legacy_spec.rb
236
- - spec/spec_tests/corpus_spec.rb
236
+ - spec/spec_tests/data/corpus/decimal128-7.json
237
+ - spec/spec_tests/data/corpus/top.json
237
238
  - spec/spec_tests/data/corpus/array.json
239
+ - spec/spec_tests/data/corpus/null.json
238
240
  - spec/spec_tests/data/corpus/document.json
239
- - spec/spec_tests/data/corpus/decimal128-7.json
240
- - spec/spec_tests/data/corpus/decimal128-3.json
241
- - spec/spec_tests/data/corpus/maxkey.json
242
- - spec/spec_tests/data/corpus/code.json
243
- - spec/spec_tests/data/corpus/dbpointer.json
244
- - spec/spec_tests/data/corpus/int32.json
245
- - spec/spec_tests/data/corpus/README.md
246
- - spec/spec_tests/data/corpus/decimal128-5.json
247
- - spec/spec_tests/data/corpus/decimal128-4.json
248
241
  - spec/spec_tests/data/corpus/decimal128-2.json
249
- - spec/spec_tests/data/corpus/double.json
250
- - spec/spec_tests/data/corpus/code_w_scope.json
242
+ - spec/spec_tests/data/corpus/decimal128-6.json
243
+ - spec/spec_tests/data/corpus/boolean.json
244
+ - spec/spec_tests/data/corpus/README.md
245
+ - spec/spec_tests/data/corpus/maxkey.json
251
246
  - spec/spec_tests/data/corpus/binary.json
247
+ - spec/spec_tests/data/corpus/multi-type.json
248
+ - spec/spec_tests/data/corpus/timestamp.json
249
+ - spec/spec_tests/data/corpus/multi-type-deprecated.json
250
+ - spec/spec_tests/data/corpus/dbpointer.json
252
251
  - spec/spec_tests/data/corpus/oid.json
253
- - spec/spec_tests/data/corpus/null.json
254
- - spec/spec_tests/data/corpus/decimal128-6.json
255
- - spec/spec_tests/data/corpus/int64.json
256
- - spec/spec_tests/data/corpus/dbref.json
257
252
  - spec/spec_tests/data/corpus/regex.json
258
253
  - spec/spec_tests/data/corpus/minkey.json
259
- - spec/spec_tests/data/corpus/multi-type.json
260
- - spec/spec_tests/data/corpus/top.json
261
254
  - spec/spec_tests/data/corpus/symbol.json
262
- - spec/spec_tests/data/corpus/multi-type-deprecated.json
255
+ - spec/spec_tests/data/corpus/dbref.json
256
+ - spec/spec_tests/data/corpus/decimal128-1.json
263
257
  - spec/spec_tests/data/corpus/undefined.json
264
- - spec/spec_tests/data/corpus/datetime.json
258
+ - spec/spec_tests/data/corpus/double.json
259
+ - spec/spec_tests/data/corpus/decimal128-4.json
260
+ - spec/spec_tests/data/corpus/decimal128-3.json
261
+ - spec/spec_tests/data/corpus/decimal128-5.json
262
+ - spec/spec_tests/data/corpus/int32.json
265
263
  - spec/spec_tests/data/corpus/string.json
266
- - spec/spec_tests/data/corpus/boolean.json
267
- - spec/spec_tests/data/corpus/timestamp.json
268
- - spec/spec_tests/data/corpus/decimal128-1.json
269
- - spec/spec_tests/data/decimal128/decimal128-7.json
270
- - spec/spec_tests/data/decimal128/decimal128-3.json
271
- - spec/spec_tests/data/decimal128/decimal128-5.json
272
- - spec/spec_tests/data/decimal128/decimal128-4.json
273
- - spec/spec_tests/data/decimal128/decimal128-2.json
274
- - spec/spec_tests/data/decimal128/decimal128-6.json
275
- - spec/spec_tests/data/decimal128/decimal128-1.json
264
+ - spec/spec_tests/data/corpus/code.json
265
+ - spec/spec_tests/data/corpus/code_w_scope.json
266
+ - spec/spec_tests/data/corpus/int64.json
267
+ - spec/spec_tests/data/corpus/datetime.json
268
+ - spec/spec_tests/data/corpus_legacy/top.json
276
269
  - spec/spec_tests/data/corpus_legacy/array.json
270
+ - spec/spec_tests/data/corpus_legacy/null.json
277
271
  - spec/spec_tests/data/corpus_legacy/document.json
272
+ - spec/spec_tests/data/corpus_legacy/boolean.json
278
273
  - spec/spec_tests/data/corpus_legacy/maxkey.json
279
- - spec/spec_tests/data/corpus_legacy/code.json
280
- - spec/spec_tests/data/corpus_legacy/int32.json
281
- - spec/spec_tests/data/corpus_legacy/double.json
282
- - spec/spec_tests/data/corpus_legacy/code_w_scope.json
283
274
  - spec/spec_tests/data/corpus_legacy/binary.json
275
+ - spec/spec_tests/data/corpus_legacy/timestamp.json
284
276
  - spec/spec_tests/data/corpus_legacy/oid.json
285
- - spec/spec_tests/data/corpus_legacy/null.json
286
277
  - spec/spec_tests/data/corpus_legacy/regex.json
287
278
  - spec/spec_tests/data/corpus_legacy/minkey.json
288
- - spec/spec_tests/data/corpus_legacy/top.json
289
279
  - spec/spec_tests/data/corpus_legacy/undefined.json
280
+ - spec/spec_tests/data/corpus_legacy/double.json
281
+ - spec/spec_tests/data/corpus_legacy/int32.json
290
282
  - spec/spec_tests/data/corpus_legacy/string.json
291
- - spec/spec_tests/data/corpus_legacy/boolean.json
292
- - spec/spec_tests/data/corpus_legacy/timestamp.json
283
+ - spec/spec_tests/data/corpus_legacy/code.json
284
+ - spec/spec_tests/data/corpus_legacy/code_w_scope.json
293
285
  - spec/spec_tests/data/corpus_legacy/failures/dbpointer.json
294
- - spec/spec_tests/data/corpus_legacy/failures/int64.json
295
286
  - spec/spec_tests/data/corpus_legacy/failures/symbol.json
287
+ - spec/spec_tests/data/corpus_legacy/failures/int64.json
296
288
  - spec/spec_tests/data/corpus_legacy/failures/datetime.json
297
- - spec/runners/corpus.rb
298
- - spec/runners/corpus_legacy.rb
299
- - spec/runners/common_driver.rb
300
- - spec/support/spec_config.rb
301
- - spec/support/shared_examples.rb
289
+ - spec/spec_tests/data/decimal128/decimal128-7.json
290
+ - spec/spec_tests/data/decimal128/decimal128-2.json
291
+ - spec/spec_tests/data/decimal128/decimal128-6.json
292
+ - spec/spec_tests/data/decimal128/decimal128-1.json
293
+ - spec/spec_tests/data/decimal128/decimal128-4.json
294
+ - spec/spec_tests/data/decimal128/decimal128-3.json
295
+ - spec/spec_tests/data/decimal128/decimal128-5.json
302
296
  - spec/support/utils.rb
303
- - spec/bson/ext_json_parse_spec.rb
304
- - spec/bson/object_spec.rb
305
- - spec/bson/json_spec.rb
306
- - spec/bson/true_class_spec.rb
297
+ - spec/support/shared_examples.rb
298
+ - spec/support/spec_config.rb
299
+ - spec/runners/common_driver.rb
300
+ - spec/runners/corpus_legacy.rb
301
+ - spec/runners/corpus.rb
302
+ - spec/bson/code_spec.rb
307
303
  - spec/bson/byte_buffer_read_spec.rb
308
- - spec/bson/config_spec.rb
309
304
  - spec/bson/int32_spec.rb
310
- - spec/bson/regexp_spec.rb
311
- - spec/bson/symbol_raw_spec.rb
312
- - spec/bson/open_struct_spec.rb
305
+ - spec/bson/max_key_spec.rb
306
+ - spec/bson/time_spec.rb
307
+ - spec/bson/array_spec.rb
308
+ - spec/bson/date_time_spec.rb
313
309
  - spec/bson/document_spec.rb
314
- - spec/bson/min_key_spec.rb
310
+ - spec/bson/float_spec.rb
311
+ - spec/bson/nil_class_spec.rb
312
+ - spec/bson/time_with_zone_spec.rb
313
+ - spec/bson/ext_json_parse_spec.rb
314
+ - spec/bson/string_spec.rb
315
+ - spec/bson/open_struct_spec.rb
316
+ - spec/bson/config_spec.rb
315
317
  - spec/bson/false_class_spec.rb
316
- - spec/bson/code_spec.rb
317
- - spec/bson/symbol_spec.rb
318
- - spec/bson/object_id_spec.rb
318
+ - spec/bson/raw_spec.rb
319
+ - spec/bson/regexp_spec.rb
320
+ - spec/bson/binary_spec.rb
321
+ - spec/bson/object_spec.rb
319
322
  - spec/bson/decimal128_spec.rb
320
- - spec/bson/registry_spec.rb
321
- - spec/bson/time_spec.rb
323
+ - spec/bson/binary_uuid_spec.rb
322
324
  - spec/bson/boolean_spec.rb
323
325
  - spec/bson/byte_buffer_spec.rb
324
- - spec/bson/hash_spec.rb
326
+ - spec/bson/json_spec.rb
327
+ - spec/bson/symbol_spec.rb
328
+ - spec/bson/integer_spec.rb
329
+ - spec/bson/byte_buffer_write_spec.rb
330
+ - spec/bson/registry_spec.rb
331
+ - spec/bson/code_with_scope_spec.rb
332
+ - spec/bson/true_class_spec.rb
325
333
  - spec/bson/undefined_spec.rb
326
- - spec/bson/raw_spec.rb
327
- - spec/bson/string_spec.rb
334
+ - spec/bson/object_id_spec.rb
328
335
  - spec/bson/timestamp_spec.rb
329
- - spec/bson/date_time_spec.rb
330
- - spec/bson/max_key_spec.rb
336
+ - spec/bson/hash_spec.rb
337
+ - spec/bson/symbol_raw_spec.rb
338
+ - spec/bson/min_key_spec.rb
331
339
  - spec/bson/int64_spec.rb
332
- - spec/bson/byte_buffer_write_spec.rb
333
340
  - spec/bson/date_spec.rb
334
- - spec/bson/binary_spec.rb
335
- - spec/bson/code_with_scope_spec.rb
336
- - spec/bson/integer_spec.rb
337
- - spec/bson/binary_uuid_spec.rb
338
- - spec/bson/nil_class_spec.rb
339
- - spec/bson/array_spec.rb
340
- - spec/bson/time_with_zone_spec.rb
341
- - spec/bson/float_spec.rb
metadata.gz.sig CHANGED
Binary file
Binary file