bson 4.11.1-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: 725cd0cbc7f1ffe6b21db7a0bba75f06004cfe840bdc960ec3e800017b655bcd
4
- data.tar.gz: ded62238e5d764555a8325e22832383413923fd794f5f342bc908d97868e1676
3
+ metadata.gz: fdf6c4e223ffb2096c37888da541dfc5c1d93d0776f13411f48c1a5db88ccf20
4
+ data.tar.gz: b2451c9140eaf9c2357db2f90c0890c3e81fe27dbe490d8c6e600f2c4926a779
5
5
  SHA512:
6
- metadata.gz: 6d0b0a456f5bf8ac39396cceb105f7ef0f28cf17694583e4da3d9fb4385e8852151b1408ea15e77a27154013602f317f67ab8b2be83cae195fe579c34723ce0b
7
- data.tar.gz: c21d38cb8696363b1ddbc87c781e2109b236ba99de9dfb86e9daa8cabacf230b83d84f06d68bbebbe7aafa6598358d77a395a6ee2426fc337b5cbaa07510b10c
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
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}"
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.11.1".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
@@ -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
@@ -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
  }
@@ -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.11.1
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
+ ZXItcnVieS9EQz0xM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F49jBu0dHaz
31
+ MRghinst6ROS1qVRae0z+wkbnufpH/NxdCUufb639nAlZguT2rGqvM6VZCC8eSO9
32
+ KfJA7/MEE+qQtiQgJaAUVRaGC8fLtmS555BPjNVITJs+BcGDYWh2clWuqlzjHOp3
33
+ YoFhlyUEi7VLlqNH0H/JFttVZK6+qmLelkVNcIYVLeWOB4Lf4VxEiYGEK1ORxsrY
34
+ iyYKJJALWY1FAInGRIlvkN+B8o3yIhq1
35
35
  -----END CERTIFICATE-----
36
- date: 2020-11-04 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:
metadata.gz.sig CHANGED
Binary file