bson 4.11.1 → 4.12.0

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: 6f2b7b7906a18c900a2cd45e1b884f3c84cf863234e703838ee752c6b87badcb
4
- data.tar.gz: beb2dd92cc828d7db3084ff2095a8df28dcb6a18e89c699f2a6bd7b7d1acd376
3
+ metadata.gz: 3662e6dcaeb6d1abeb9e550812644bcf906ecf5342ad98e5e72e556924789102
4
+ data.tar.gz: b224d635c9394d2798123d33cdc34a82a9955c25bdf82864d42e24bf8f3820d1
5
5
  SHA512:
6
- metadata.gz: 5e0359cf8b6632840e5ad9be71f5d350a53e0606d5fa5afa4706021f1083a9493a410bc8d9d5ecc24c6b3ba02f7ee482898db9dc190ff8620ad5dc9014441e90
7
- data.tar.gz: beb107c6db4bd7f6ba32671d4d340f9593636fe490b69e6e60abc812c1698b4f203b800f2ea145af77a9c319b7c9f4dfa90bb22eea157d15828a09bc8fb388ae
6
+ metadata.gz: b85af4ca697de6dbff5fc6acb1cbbcbd6299a5d4424e2e3e9963f9725262b8feaf3043a60e7725439c5ba26b652ff021191cc4aa093d572369ca9884bd6da89a
7
+ data.tar.gz: 4515e64a7078cf06e9683bf90693b358949582986145a81d9fe180a1fad18fa4aeb20b4f8bcebc0a3f1c5e1ba2496699e3763a81a61138b53fbb4c2b4c1741ef
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1 @@
1
- Oi���a�H�V /ZH���LaØ��+�<�.}39X|7����yH��;ҢrsA��y��/N9s��g-����6p{=��vJ1��{\3���쇮�E����� ��((�co)�~
2
- �vȿw�y�jR�Ҏ~�$N���P�����Ӿhr�����f�Yk��J�]υr�5�e�yA���NV�ў�H���#^2���Xg����޸ *_�ߌ��hQY6D������p�T�&�p�����?�
1
+ v����_E�:�����ZxBr%�4,G�ʹ�X,>m%�*x��X���Ɂ�S�G$"D��O!��d6O�R�a��Ao��54ٞ�bCavI�i3���d�G�� &�C@rl���^m"�힝)L��2b J����g��ɖ�&� m��P�k5��!���ͳ����Т|1�#K����9��HhMl{U�����,Y������ç;��Q`��Ȯؿ�����ī�.|����6�=qbJ���'z
data.tar.gz.sig 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: ruby
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-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
@@ -1,2 +1 @@
1
- 
2
- ��oF\O��+��(��D�jt�oR�ީ�j1������E�7�~m�ЊNJ��.�>���/e��"1B�hk�TJ7�+���O��P������$�-[�Y
1
+ m�{'nC{")��X��`����K�4q���*j��=�̾.��.ʩC9,h����f3�y�>�]O�e]f���ɓk ��14W��A�g\\�A���i4rpDD���m3�\Vw���eap���!w�r>'���:�u]/gn��cr��m��׬��Ń~�h�;�ORF}�9b�?���H�ԧ�� |��Oi���xp�74� ����]���P:�H�G��v[���_��X��5j�ݮ��~W���45#kkY�.��K|