bson 4.12.1 → 4.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +4 -7
  4. data/ext/bson/bson-native.h +2 -0
  5. data/ext/bson/init.c +9 -0
  6. data/ext/bson/read.c +29 -0
  7. data/lib/bson/active_support.rb +1 -0
  8. data/lib/bson/array.rb +2 -1
  9. data/lib/bson/binary.rb +5 -3
  10. data/lib/bson/boolean.rb +2 -1
  11. data/lib/bson/code.rb +2 -1
  12. data/lib/bson/code_with_scope.rb +2 -1
  13. data/lib/bson/config.rb +1 -0
  14. data/lib/bson/date.rb +1 -0
  15. data/lib/bson/date_time.rb +1 -0
  16. data/lib/bson/db_pointer.rb +2 -1
  17. data/lib/bson/dbref.rb +125 -0
  18. data/lib/bson/decimal128/builder.rb +18 -15
  19. data/lib/bson/decimal128.rb +10 -9
  20. data/lib/bson/document.rb +14 -0
  21. data/lib/bson/environment.rb +1 -0
  22. data/lib/bson/error.rb +7 -0
  23. data/lib/bson/ext_json.rb +16 -11
  24. data/lib/bson/false_class.rb +2 -1
  25. data/lib/bson/float.rb +20 -31
  26. data/lib/bson/hash.rb +15 -6
  27. data/lib/bson/int32.rb +3 -2
  28. data/lib/bson/int64.rb +3 -2
  29. data/lib/bson/integer.rb +3 -2
  30. data/lib/bson/json.rb +1 -0
  31. data/lib/bson/max_key.rb +3 -2
  32. data/lib/bson/min_key.rb +3 -2
  33. data/lib/bson/nil_class.rb +2 -1
  34. data/lib/bson/object.rb +1 -0
  35. data/lib/bson/object_id.rb +4 -3
  36. data/lib/bson/open_struct.rb +1 -0
  37. data/lib/bson/regexp.rb +17 -6
  38. data/lib/bson/registry.rb +1 -0
  39. data/lib/bson/specialized.rb +1 -0
  40. data/lib/bson/string.rb +3 -2
  41. data/lib/bson/symbol.rb +2 -1
  42. data/lib/bson/time.rb +4 -3
  43. data/lib/bson/time_with_zone.rb +1 -0
  44. data/lib/bson/timestamp.rb +3 -2
  45. data/lib/bson/true_class.rb +2 -1
  46. data/lib/bson/undefined.rb +2 -1
  47. data/lib/bson/version.rb +2 -1
  48. data/lib/bson.rb +6 -4
  49. data/spec/README.md +14 -0
  50. data/spec/bson/dbref_spec.rb +461 -0
  51. data/spec/bson/document_spec.rb +7 -1
  52. data/spec/bson/ext_json_parse_spec.rb +37 -0
  53. data/spec/bson/int64_spec.rb +4 -24
  54. data/spec/bson/raw_spec.rb +7 -1
  55. data/spec/bson/regexp_spec.rb +52 -0
  56. data/spec/runners/common_driver.rb +1 -1
  57. data/spec/shared/LICENSE +20 -0
  58. data/spec/shared/bin/get-mongodb-download-url +17 -0
  59. data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
  60. data/spec/shared/lib/mrss/cluster_config.rb +221 -0
  61. data/spec/shared/lib/mrss/constraints.rb +346 -0
  62. data/spec/shared/lib/mrss/docker_runner.rb +265 -0
  63. data/spec/shared/lib/mrss/lite_constraints.rb +191 -0
  64. data/spec/shared/lib/mrss/server_version_registry.rb +115 -0
  65. data/spec/shared/lib/mrss/spec_organizer.rb +152 -0
  66. data/spec/shared/lib/mrss/utils.rb +15 -0
  67. data/spec/shared/share/Dockerfile.erb +231 -0
  68. data/spec/shared/shlib/distro.sh +73 -0
  69. data/spec/shared/shlib/server.sh +290 -0
  70. data/spec/shared/shlib/set_env.sh +128 -0
  71. data/spec/spec_helper.rb +9 -1
  72. data/spec/spec_tests/data/corpus/binary.json +5 -0
  73. data/spec/spec_tests/data/corpus/dbref.json +21 -1
  74. data/spec/spec_tests/data/corpus/document.json +4 -0
  75. data/spec/spec_tests/data/corpus/regex.json +2 -2
  76. data/spec/spec_tests/data/corpus/top.json +20 -9
  77. data.tar.gz.sig +0 -0
  78. metadata +123 -90
  79. metadata.gz.sig +0 -0
@@ -0,0 +1,461 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ require 'spec_helper'
5
+ require 'json'
6
+
7
+ describe BSON::DBRef do
8
+
9
+ let(:object_id) do
10
+ BSON::ObjectId.new
11
+ end
12
+
13
+ describe '#as_json' do
14
+
15
+ context 'when the database is not provided' do
16
+
17
+ let(:dbref) do
18
+ described_class.new({ '$ref' => 'users', '$id' => object_id })
19
+ end
20
+
21
+ it 'returns the json document without database' do
22
+ expect(dbref.as_json).to eq({ '$ref' => 'users', '$id' => object_id })
23
+ end
24
+ end
25
+
26
+ context 'when the database is provided' do
27
+
28
+ let(:dbref) do
29
+ described_class.new({ '$ref' => 'users', '$id' => object_id, '$db' => 'database' })
30
+ end
31
+
32
+ it 'returns the json document with database' do
33
+ expect(dbref.as_json).to eq({
34
+ '$ref' => 'users',
35
+ '$id' => object_id,
36
+ '$db' => 'database'
37
+ })
38
+ end
39
+ end
40
+
41
+ context 'when other keys are provided' do
42
+
43
+ let(:dbref) do
44
+ described_class.new({ '$ref' => 'users', '$id' => object_id, '$db' => 'database', 'x' => 'y' })
45
+ end
46
+
47
+ it 'returns the json document with the other keys' do
48
+ expect(dbref.as_json).to eq({
49
+ '$ref' => 'users',
50
+ '$id' => object_id,
51
+ '$db' => 'database',
52
+ 'x' => 'y'
53
+ })
54
+ end
55
+ end
56
+ end
57
+
58
+ describe '#initialize' do
59
+
60
+ let(:dbref) do
61
+ described_class.new(hash)
62
+ end
63
+
64
+ let(:hash) do
65
+ { '$ref' => 'users', '$id' => object_id }
66
+ end
67
+
68
+ it 'sets the collection' do
69
+ expect(dbref.collection).to eq('users')
70
+ end
71
+
72
+ it 'sets the id' do
73
+ expect(dbref.id).to eq(object_id)
74
+ end
75
+
76
+ context 'when a database is provided' do
77
+
78
+ let(:hash) do
79
+ { '$ref' => 'users', '$id' => object_id, '$db' => 'db' }
80
+ end
81
+
82
+ it 'sets the database' do
83
+ expect(dbref.database).to eq('db')
84
+ end
85
+ end
86
+
87
+ context 'when not providing a collection' do
88
+ let(:hash) do
89
+ { '$id' => object_id, '$db' => 'db' }
90
+ end
91
+
92
+ it 'raises an error' do
93
+ expect do
94
+ dbref
95
+ end.to raise_error(ArgumentError, /DBRef must have \$ref/)
96
+ end
97
+ end
98
+
99
+ context 'when not providing an id' do
100
+ let(:hash) do
101
+ { '$ref' => 'users', '$db' => 'db' }
102
+ end
103
+
104
+ it 'raises an error' do
105
+ expect do
106
+ dbref
107
+ end.to raise_error(ArgumentError, /DBRef must have \$id/)
108
+ end
109
+ end
110
+
111
+ context 'when providing an invalid type for ref' do
112
+ let(:hash) do
113
+ { '$ref' => 1, '$id' => object_id }
114
+ end
115
+
116
+ it 'raises an error' do
117
+ expect do
118
+ dbref
119
+ end.to raise_error(ArgumentError, /The value for key \$ref must be a string/)
120
+ end
121
+ end
122
+
123
+ context 'when providing an invalid type for database' do
124
+ let(:hash) do
125
+ { '$ref' => 'users', '$id' => object_id, '$db' => 1 }
126
+ end
127
+
128
+ it 'raises an error' do
129
+ expect do
130
+ dbref
131
+ end.to raise_error(ArgumentError, /The value for key \$db must be a string/)
132
+ end
133
+ end
134
+
135
+ context 'when providing the fieds as symbols' do
136
+ let(:hash) do
137
+ { :$ref => 'users', :$id => object_id, :$db => 'db' }
138
+ end
139
+
140
+ it 'does not raise an error' do
141
+ expect do
142
+ dbref
143
+ end.to_not raise_error
144
+ end
145
+ end
146
+
147
+ context 'when testing the ordering of the fields' do
148
+ context 'when the fields are in order' do
149
+ let(:hash) do
150
+ { '$ref' => 'users', '$id' => object_id, '$db' => 'db' }
151
+ end
152
+
153
+ it 'has the correct order' do
154
+ expect(dbref.keys).to eq(['$ref', '$id', '$db'])
155
+ end
156
+ end
157
+
158
+ context 'when the fields are out of order' do
159
+ let(:hash) do
160
+ { '$db' => 'db', '$id' => object_id, '$ref' => 'users' }
161
+ end
162
+
163
+ it 'has the correct order' do
164
+ expect(dbref.keys).to eq(['$ref', '$id', '$db'])
165
+ end
166
+ end
167
+
168
+ context 'when there is no db' do
169
+ let(:hash) do
170
+ { '$id' => object_id, '$ref' => 'users' }
171
+ end
172
+
173
+ it 'has the correct order' do
174
+ expect(dbref.keys).to eq(['$ref', '$id'])
175
+ end
176
+ end
177
+
178
+ context 'when the there are other fields in order' do
179
+ let(:hash) do
180
+ { '$ref' => 'users', '$id' => object_id, '$db' => 'db', 'x' => 'y', 'y' => 'z' }
181
+ end
182
+
183
+ it 'has the correct order' do
184
+ expect(dbref.keys).to eq(['$ref', '$id', '$db', 'x', 'y'])
185
+ end
186
+ end
187
+
188
+ context 'when the there are other fields out of order' do
189
+ let(:hash) do
190
+ { 'y' => 'z', '$db' => 'db', '$id' => object_id, 'x' => 'y', '$ref' => 'users' }
191
+ end
192
+
193
+ it 'has the correct order' do
194
+ expect(dbref.keys).to eq(['$ref', '$id', '$db', 'y', 'x'])
195
+ end
196
+ end
197
+ end
198
+ end
199
+
200
+ describe '#to_bson' do
201
+
202
+ let(:dbref) do
203
+ described_class.new({ '$ref' => 'users', '$id' => object_id, '$db' => 'database' })
204
+ end
205
+
206
+ it 'converts the underlying document to bson' do
207
+ expect(dbref.to_bson.to_s).to eq(dbref.as_json.to_bson.to_s)
208
+ end
209
+ end
210
+
211
+ describe '#to_json' do
212
+
213
+ context 'when the database is not provided' do
214
+
215
+ let(:dbref) do
216
+ described_class.new({ '$ref' => 'users', '$id' => object_id })
217
+ end
218
+
219
+ it 'returns the json document without database' do
220
+ expect(dbref.to_json).to eq("{\"$ref\":\"users\",\"$id\":#{object_id.to_json}}")
221
+ end
222
+ end
223
+
224
+ context 'when the database is provided' do
225
+
226
+ let(:dbref) do
227
+ described_class.new({ '$ref' => 'users', '$id' => object_id, '$db' => 'database' })
228
+ end
229
+
230
+ it 'returns the json document with database' do
231
+ expect(dbref.to_json).to eq("{\"$ref\":\"users\",\"$id\":#{object_id.to_json},\"$db\":\"database\"}")
232
+ end
233
+ end
234
+
235
+ context 'when other keys are provided' do
236
+
237
+ let(:dbref) do
238
+ described_class.new({ '$ref' => 'users', '$id' => object_id, '$db' => 'database', 'x' => 'y' })
239
+ end
240
+
241
+ it 'returns the json document with the other keys' do
242
+ expect(dbref.to_json).to eq("{\"$ref\":\"users\",\"$id\":#{object_id.to_json},\"$db\":\"database\",\"x\":\"y\"}")
243
+ end
244
+ end
245
+ end
246
+
247
+ describe '#from_bson' do
248
+
249
+ let(:buffer) do
250
+ hash.to_bson
251
+ end
252
+
253
+ let(:decoded) do
254
+ BSON::Document.from_bson(BSON::ByteBuffer.new(buffer.to_s))
255
+ end
256
+
257
+ context 'when a database exists' do
258
+
259
+ let(:hash) do
260
+ { '$ref' => 'users', '$id' => object_id, '$db' => 'database' }
261
+ end
262
+
263
+ it 'decodes the ref' do
264
+ expect(decoded.collection).to eq('users')
265
+ end
266
+
267
+ it 'decodes the id' do
268
+ expect(decoded.id).to eq(object_id)
269
+ end
270
+
271
+ it 'decodes the database' do
272
+ expect(decoded.database).to eq('database')
273
+ end
274
+
275
+ it 'is of class DBRef' do
276
+ expect(decoded).to be_a described_class
277
+ end
278
+ end
279
+
280
+ context 'when no database exists' do
281
+
282
+ let(:hash) do
283
+ { '$ref' => 'users', '$id' => object_id }
284
+ end
285
+
286
+ it 'decodes the ref' do
287
+ expect(decoded.collection).to eq('users')
288
+ end
289
+
290
+ it 'decodes the id' do
291
+ expect(decoded.id).to eq(object_id)
292
+ end
293
+
294
+ it 'sets the database to nil' do
295
+ expect(decoded.database).to be_nil
296
+ end
297
+
298
+ it 'is of class DBRef' do
299
+ expect(decoded).to be_a described_class
300
+ end
301
+ end
302
+
303
+ context 'when other keys exist' do
304
+
305
+ let(:hash) do
306
+ { '$ref' => 'users', '$id' => object_id, 'x' => 'y' }
307
+ end
308
+
309
+ it 'decodes the key' do
310
+ expect(decoded['x']).to eq('y')
311
+ end
312
+
313
+ it 'is of class DBRef' do
314
+ expect(decoded).to be_a described_class
315
+ end
316
+ end
317
+
318
+ context 'when it is an invalid dbref' do
319
+
320
+ shared_examples 'bson document' do
321
+ it 'should not raise' do
322
+ expect do
323
+ decoded
324
+ end.to_not raise_error
325
+ end
326
+
327
+ it 'has the correct class' do
328
+ expect(decoded).to be_a BSON::Document
329
+ expect(decoded).to_not be_a described_class
330
+ end
331
+ end
332
+
333
+ context 'when the hash has invalid collection type' do
334
+ let(:hash) do
335
+ { '$ref' => 1, '$id' => object_id }
336
+ end
337
+ include_examples 'bson document'
338
+ end
339
+
340
+ context 'when the hash has an invalid database type' do
341
+ let(:hash) do
342
+ { '$ref' => 'users', '$id' => object_id, '$db' => 1 }
343
+ end
344
+ include_examples 'bson document'
345
+ end
346
+
347
+ context 'when the hash is missing a collection' do
348
+ let(:hash) do
349
+ { '$id' => object_id }
350
+ end
351
+ include_examples 'bson document'
352
+ end
353
+
354
+ context 'when the hash is missing an id' do
355
+ let(:hash) do
356
+ { '$ref' => 'users' }
357
+ end
358
+ include_examples 'bson document'
359
+ end
360
+ end
361
+
362
+ context 'when nesting the dbref' do
363
+
364
+ context 'when it is a valid dbref' do
365
+ let(:hash) do
366
+ { 'dbref' => { '$ref' => 'users', '$id' => object_id } }
367
+ end
368
+
369
+ it 'should not raise' do
370
+ expect do
371
+ buffer
372
+ end.to_not raise_error
373
+ end
374
+
375
+ it 'has the correct class' do
376
+ expect(decoded['dbref']).to be_a described_class
377
+ end
378
+ end
379
+
380
+ context 'when it is an invalid dbref' do
381
+
382
+ shared_examples 'nested bson document' do
383
+ it 'should not raise' do
384
+ expect do
385
+ decoded
386
+ end.to_not raise_error
387
+ end
388
+
389
+ it 'has the correct class' do
390
+ expect(decoded['dbref']).to be_a BSON::Document
391
+ expect(decoded['dbref']).to_not be_a described_class
392
+ end
393
+ end
394
+
395
+ context 'when the hash has invalid collection type' do
396
+ let(:hash) do
397
+ { 'dbref' => { '$ref' => 1, '$id' => object_id } }
398
+ end
399
+ include_examples 'nested bson document'
400
+ end
401
+
402
+ context 'when the hash has an invalid database type' do
403
+ let(:hash) do
404
+ { 'dbref' => { '$ref' => 'users', '$id' => object_id, '$db' => 1 } }
405
+ end
406
+ include_examples 'nested bson document'
407
+ end
408
+
409
+ context 'when the hash is missing a collection' do
410
+ let(:hash) do
411
+ { 'dbref' => { '$id' => object_id } }
412
+ end
413
+ include_examples 'nested bson document'
414
+ end
415
+
416
+ context 'when the hash is missing an id' do
417
+ let(:hash) do
418
+ { 'dbref' => { '$ref' => 'users' } }
419
+ end
420
+ include_examples 'nested bson document'
421
+ end
422
+ end
423
+ end
424
+
425
+ context 'when nesting a dbref inside a dbref' do
426
+ context 'when it is a valid dbref' do
427
+ let(:hash) do
428
+ { 'dbref1' => { '$ref' => 'users', '$id' => object_id, 'dbref2' => { '$ref' => 'users', '$id' => object_id } } }
429
+ end
430
+
431
+ it 'should not raise' do
432
+ expect do
433
+ buffer
434
+ end.to_not raise_error
435
+ end
436
+
437
+ it 'has the correct class' do
438
+ expect(decoded['dbref1']).to be_a described_class
439
+ expect(decoded['dbref1']['dbref2']).to be_a described_class
440
+ end
441
+ end
442
+
443
+ context 'when it is an invalid dbref' do
444
+ let(:hash) do
445
+ { 'dbref' => { '$ref' => 'users', '$id' => object_id, 'dbref' => { '$ref' => 1, '$id' => object_id } } }
446
+ end
447
+
448
+ it 'should not raise' do
449
+ expect do
450
+ decoded
451
+ end.to_not raise_error
452
+ end
453
+
454
+ it 'has the correct class' do
455
+ expect(decoded['dbref']).to be_a described_class
456
+ expect(decoded['dbref']['dbref']).to be_a BSON::Document
457
+ end
458
+ end
459
+ end
460
+ end
461
+ end
@@ -520,7 +520,13 @@ describe BSON::Document do
520
520
  context "when the document has been serialized" do
521
521
 
522
522
  let(:deserialized) do
523
- YAML.load(YAML.dump(doc))
523
+ if YAML.respond_to?(:unsafe_load)
524
+ # In psych >= 4.0.0 `load` is basically an alias to `safe_load`,
525
+ # which will fail here.
526
+ YAML.unsafe_load(YAML.dump(doc))
527
+ else
528
+ YAML.load(YAML.dump(doc))
529
+ end
524
530
  end
525
531
 
526
532
  let!(:enum) do
@@ -148,6 +148,7 @@ describe "BSON::ExtJSON.parse" do
148
148
  end
149
149
 
150
150
  let(:parsed) { BSON::ExtJSON.parse_obj(input, mode: mode) }
151
+ let(:mode) { :bson }
151
152
 
152
153
  context 'when mode is invalid' do
153
154
  let(:mode) { :foo }
@@ -158,6 +159,42 @@ describe "BSON::ExtJSON.parse" do
158
159
  end.should raise_error(ArgumentError, /Invalid value for :mode option/)
159
160
  end
160
161
  end
162
+
163
+ context 'when it contains a string key with a null byte' do
164
+ let(:input) do
165
+ { "key\x00" => 1 }
166
+ end
167
+
168
+ it 'raises an exception' do
169
+ lambda do
170
+ parsed
171
+ end.should raise_error(BSON::Error::ExtJSONParseError, /Hash key cannot contain a null byte/)
172
+ end
173
+ end
174
+
175
+ context 'when it contains a symbol key with a null byte' do
176
+ let(:input) do
177
+ { "key\x00".to_sym => 1 }
178
+ end
179
+
180
+ it 'raises an exception' do
181
+ lambda do
182
+ parsed
183
+ end.should raise_error(BSON::Error::ExtJSONParseError, /Hash key cannot contain a null byte/)
184
+ end
185
+ end
186
+
187
+ context 'when it contains an integer key' do
188
+ let(:input) do
189
+ { 0 => 1 }
190
+ end
191
+
192
+ it 'does not raises an exception' do
193
+ lambda do
194
+ parsed
195
+ end.should_not raise_error
196
+ end
197
+ end
161
198
  end
162
199
 
163
200
  context 'when input is a binary' do
@@ -106,18 +106,8 @@ describe BSON::Int64 do
106
106
  end
107
107
  end
108
108
 
109
- context "when using MRI < 2.4", if: (!BSON::Environment.jruby? && RUBY_VERSION < '2.4') do
110
-
111
- it "deserializes to a Fixnum object" do
112
- expect(described_class.from_bson(bson).class).to be(Fixnum)
113
- end
114
- end
115
-
116
- context "when using MRI >= 2.4", if: (!BSON::Environment.jruby? && RUBY_VERSION >= '2.4') do
117
-
118
- it "deserializes to an Integer object" do
119
- expect(described_class.from_bson(bson).class).to be(Integer)
120
- end
109
+ it "deserializes to an Integer object" do
110
+ expect(described_class.from_bson(bson).class).to be(Integer)
121
111
  end
122
112
  end
123
113
 
@@ -136,18 +126,8 @@ describe BSON::Int64 do
136
126
  end
137
127
  end
138
128
 
139
- context "when using MRI < 2.4", if: (!BSON::Environment.jruby? && RUBY_VERSION < '2.4') do
140
-
141
- it "deserializes to a Bignum object" do
142
- expect(described_class.from_bson(bson).class).to be(Bignum)
143
- end
144
- end
145
-
146
- context "when using MRI >= 2.4", if: (!BSON::Environment.jruby? && RUBY_VERSION >= '2.4') do
147
-
148
- it "deserializes to an Integer object" do
149
- expect(described_class.from_bson(bson).class).to be(Integer)
150
- end
129
+ it "deserializes to an Integer object" do
130
+ expect(described_class.from_bson(bson).class).to be(Integer)
151
131
  end
152
132
  end
153
133
  end
@@ -585,7 +585,13 @@ describe Regexp::Raw do
585
585
  let(:regexp) { described_class.new('hello.world', 's') }
586
586
 
587
587
  it 'round-trips' do
588
- actual = YAML.load(regexp.to_yaml)
588
+ actual = if YAML.respond_to?(:unsafe_load)
589
+ # In psych >= 4.0.0 `load` is basically an alias to `safe_load`,
590
+ # which will fail here.
591
+ YAML.unsafe_load(regexp.to_yaml)
592
+ else
593
+ YAML.load(regexp.to_yaml)
594
+ end
589
595
  actual.pattern.should == 'hello.world'
590
596
  actual.options.should == 's'
591
597
  actual.compile.should =~ "hello\nworld"
@@ -127,6 +127,58 @@ describe Regexp do
127
127
  expect(result).to eq(obj)
128
128
  end
129
129
  end
130
+
131
+ context "when the regexp options contains a null byte" do
132
+
133
+ let(:regexp) do
134
+ Regexp::Raw.new("pattern", "options\x00")
135
+ end
136
+
137
+ it "raises an error" do
138
+ expect do
139
+ regexp
140
+ end.to raise_error(BSON::Error::InvalidRegexpPattern, /Regexp options cannot contain a null byte/)
141
+ end
142
+ end
143
+
144
+ context "when the regexp options is an integer" do
145
+
146
+ let(:regexp) do
147
+ Regexp::Raw.new("pattern", 1)
148
+ end
149
+
150
+ it "doesn't raise an error" do
151
+ expect do
152
+ regexp
153
+ end.to_not raise_error
154
+ end
155
+ end
156
+
157
+ context "when the regexp options is an invalid type" do
158
+
159
+ let(:regexp) do
160
+ Regexp::Raw.new("pattern", [2])
161
+ end
162
+
163
+ it "raises an error" do
164
+ expect do
165
+ regexp
166
+ end.to raise_error(ArgumentError, /Regexp options must be a String, Symbol, or Integer/)
167
+ end
168
+ end
169
+ end
170
+
171
+ context "when the pattern contains a null byte" do
172
+
173
+ let(:regexp) do
174
+ Regexp::Raw.new("pattern\x00", "options")
175
+ end
176
+
177
+ it "raises an error" do
178
+ expect do
179
+ regexp
180
+ end.to raise_error(BSON::Error::InvalidRegexpPattern, /Regexp pattern cannot contain a null byte/)
181
+ end
130
182
  end
131
183
  end
132
184
  end
@@ -166,7 +166,7 @@ module BSON
166
166
  #
167
167
  # @since 4.2.0
168
168
  def reencoded_hex
169
- decoded_document.to_bson.to_s.unpack("H*").first.upcase
169
+ decoded_document.to_bson.to_s.unpack1("H*").upcase
170
170
  end
171
171
 
172
172
  # The object tested.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2020 MongoDB, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ desired_version, arch = ARGV
4
+ if arch.nil?
5
+ STDERR.puts "Usage: get-mongodb-download-url desired-version arch"
6
+ exit 1
7
+ end
8
+
9
+ $: << File.join(File.dirname(__FILE__), '../lib')
10
+ require 'mrss/server_version_registry'
11
+
12
+ begin
13
+ puts Mrss::ServerVersionRegistry.new(desired_version, arch).download_url
14
+ rescue Mrss::ServerVersionRegistry::Error => exc
15
+ STDERR.puts "Error: #{exc}"
16
+ exit 2
17
+ end