bson 4.9.0 → 4.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +1 -0
- data.tar.gz.sig +0 -0
- data/README.md +17 -5
- data/ext/bson/init.c +23 -21
- data/ext/bson/read.c +12 -12
- data/ext/bson/write.c +10 -3
- data/lib/bson/array.rb +3 -0
- data/lib/bson/error.rb +6 -0
- data/lib/bson/hash.rb +3 -0
- data/lib/bson/regexp.rb +7 -1
- data/lib/bson/version.rb +1 -1
- data/lib/bson_native.bundle +0 -0
- data/spec/bson/array_spec.rb +17 -0
- data/spec/bson/hash_spec.rb +17 -0
- data/spec/bson/raw_spec.rb +12 -1
- data/spec/spec_helper.rb +11 -0
- data/spec/support/spec_config.rb +6 -0
- metadata +121 -98
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e5e88dfb0ddb4d37e05be097f8b26c7a980bfc1abcc9d1e05fe40aa4130c7b5
|
4
|
+
data.tar.gz: d388af7cec7de94fa13487c78bdd747eb5bf0ac99c6aaf5a4dd012bc95e7800d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ae9d9e323587d434ce674440d0c3f980ee9aa1c8654a3a895e8dc23c66d2f4a58608f6897b1367b811f6c7fb72cccf8e4cb150fb7ca6951ba17ee3051e74eeb
|
7
|
+
data.tar.gz: 2fda4fc32c12e3d3a69dc2ba9ea35f85b784d71824e4e69268bb30898dea237f973b59be8c0fba625d13dbabb1ef2083ba56bdddb38ed0c43ecea11ffaf4afe5
|
checksums.yaml.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
@#��8n\��E�T)�ܬsgЈw��t���u`*UT�kV��'�EZ�Io�lˀj���n_!iA_�`ٻ) �ȣ��F!������թ^0��,���%&�ߚ��2�FQw��J% Pl��*e�̈́���X\���o)%�c~n�e�M{�_���͵�ˠn2R$|����/�d9H*]����d�����%4T����i2�L���t�<��� �y4��S|���<��r!���]�u�:�eLu��
|
data.tar.gz.sig
ADDED
Binary file
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
BSON
|
2
|
-
[![
|
3
|
-
[![
|
4
|
-
[![
|
5
|
-
[![
|
1
|
+
BSON
|
2
|
+
[![Gem Version][rubygems-img]][rubygems-url]
|
3
|
+
[![Build Status][travis-img]][travis-url]
|
4
|
+
[![Build status Windows][appveyor-img]][appveyor-url]
|
5
|
+
[![Coverage Status][coveralls-img]][coveralls-url]
|
6
|
+
[![Inline docs][inch-img]][inch-url]
|
6
7
|
====
|
7
8
|
|
8
9
|
An implementation of the BSON specification in Ruby.
|
@@ -51,3 +52,14 @@ distributed under the License is distributed on an "AS IS" BASIS,
|
|
51
52
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
52
53
|
See the License for the specific language governing permissions and
|
53
54
|
limitations under the License.
|
55
|
+
|
56
|
+
[rubygems-img]: https://badge.fury.io/rb/bson.svg
|
57
|
+
[rubygems-url]: http://badge.fury.io/rb/bson
|
58
|
+
[travis-img]: https://secure.travis-ci.org/mongodb/bson-ruby.svg?branch=master
|
59
|
+
[travis-url]: http://travis-ci.org/mongodb/bson-ruby
|
60
|
+
[appveyor-img]: https://ci.appveyor.com/api/projects/status/p5aqko7umsx351nm?svg=true
|
61
|
+
[appveyor-url]: https://ci.appveyor.com/project/p-mongo/bson-ruby/branch/master
|
62
|
+
[coveralls-img]: https://coveralls.io/repos/mongodb/bson-ruby/badge.svg?branch=master
|
63
|
+
[coveralls-url]: https://coveralls.io/r/mongodb/bson-ruby?branch=master
|
64
|
+
[inch-img]: http://inch-ci.org/github/mongodb/bson-ruby.svg?branch=master
|
65
|
+
[inch-url]: http://inch-ci.org/github/mongodb/bson-ruby
|
data/ext/bson/init.c
CHANGED
@@ -38,25 +38,26 @@ void Init_bson_native()
|
|
38
38
|
char rb_bson_machine_id[256];
|
39
39
|
|
40
40
|
VALUE rb_bson_module = rb_define_module("BSON");
|
41
|
-
|
41
|
+
|
42
42
|
/* Document-class: BSON::ByteBuffer
|
43
43
|
*
|
44
44
|
* Stores BSON-serialized data and provides efficient serialization and
|
45
45
|
* deserialization of common Ruby classes using native code.
|
46
46
|
*/
|
47
47
|
VALUE rb_byte_buffer_class = rb_define_class_under(rb_bson_module, "ByteBuffer", rb_cObject);
|
48
|
-
|
48
|
+
|
49
49
|
VALUE rb_bson_object_id_class = rb_const_get(rb_bson_module, rb_intern("ObjectId"));
|
50
50
|
VALUE rb_bson_object_id_generator_class = rb_const_get(rb_bson_object_id_class, rb_intern("Generator"));
|
51
51
|
VALUE rb_digest_class = rb_const_get(rb_cObject, rb_intern("Digest"));
|
52
52
|
VALUE rb_md5_class = rb_const_get(rb_digest_class, rb_intern("MD5"));
|
53
53
|
|
54
54
|
rb_bson_illegal_key = rb_const_get(rb_const_get(rb_bson_module, rb_intern("String")),rb_intern("IllegalKey"));
|
55
|
+
rb_gc_register_mark_object(rb_bson_illegal_key);
|
55
56
|
|
56
57
|
rb_define_alloc_func(rb_byte_buffer_class, rb_bson_byte_buffer_allocate);
|
57
58
|
rb_define_method(rb_byte_buffer_class, "initialize", rb_bson_byte_buffer_initialize, -1);
|
58
59
|
rb_define_method(rb_byte_buffer_class, "length", rb_bson_byte_buffer_length, 0);
|
59
|
-
|
60
|
+
|
60
61
|
/*
|
61
62
|
* call-seq:
|
62
63
|
* buffer.read_position -> Fixnum
|
@@ -64,13 +65,13 @@ void Init_bson_native()
|
|
64
65
|
* Returns the read position in the buffer.
|
65
66
|
*/
|
66
67
|
rb_define_method(rb_byte_buffer_class, "read_position", rb_bson_byte_buffer_read_position, 0);
|
67
|
-
|
68
|
+
|
68
69
|
rb_define_method(rb_byte_buffer_class, "get_byte", rb_bson_byte_buffer_get_byte, 0);
|
69
70
|
rb_define_method(rb_byte_buffer_class, "get_bytes", rb_bson_byte_buffer_get_bytes, 1);
|
70
71
|
rb_define_method(rb_byte_buffer_class, "get_cstring", rb_bson_byte_buffer_get_cstring, 0);
|
71
72
|
rb_define_method(rb_byte_buffer_class, "get_decimal128_bytes", rb_bson_byte_buffer_get_decimal128_bytes, 0);
|
72
73
|
rb_define_method(rb_byte_buffer_class, "get_double", rb_bson_byte_buffer_get_double, 0);
|
73
|
-
|
74
|
+
|
74
75
|
/*
|
75
76
|
* call-seq:
|
76
77
|
* buffer.get_hash(**options) -> Hash
|
@@ -82,7 +83,7 @@ void Init_bson_native()
|
|
82
83
|
* @return [ BSON::Document ] The decoded document.
|
83
84
|
*/
|
84
85
|
rb_define_method(rb_byte_buffer_class, "get_hash", rb_bson_byte_buffer_get_hash, -1);
|
85
|
-
|
86
|
+
|
86
87
|
/*
|
87
88
|
* call-seq:
|
88
89
|
* buffer.get_array(**options) -> Array
|
@@ -94,11 +95,11 @@ void Init_bson_native()
|
|
94
95
|
* @return [ Array ] The decoded array.
|
95
96
|
*/
|
96
97
|
rb_define_method(rb_byte_buffer_class, "get_array", rb_bson_byte_buffer_get_array, -1);
|
97
|
-
|
98
|
+
|
98
99
|
rb_define_method(rb_byte_buffer_class, "get_int32", rb_bson_byte_buffer_get_int32, 0);
|
99
100
|
rb_define_method(rb_byte_buffer_class, "get_int64", rb_bson_byte_buffer_get_int64, 0);
|
100
101
|
rb_define_method(rb_byte_buffer_class, "get_string", rb_bson_byte_buffer_get_string, 0);
|
101
|
-
|
102
|
+
|
102
103
|
/*
|
103
104
|
* call-seq:
|
104
105
|
* buffer.write_position -> Fixnum
|
@@ -106,7 +107,7 @@ void Init_bson_native()
|
|
106
107
|
* Returns the write position in the buffer.
|
107
108
|
*/
|
108
109
|
rb_define_method(rb_byte_buffer_class, "write_position", rb_bson_byte_buffer_write_position, 0);
|
109
|
-
|
110
|
+
|
110
111
|
/*
|
111
112
|
* call-seq:
|
112
113
|
* buffer.put_byte(binary_str) -> ByteBuffer
|
@@ -117,7 +118,7 @@ void Init_bson_native()
|
|
117
118
|
* Returns the modified +self+.
|
118
119
|
*/
|
119
120
|
rb_define_method(rb_byte_buffer_class, "put_byte", rb_bson_byte_buffer_put_byte, 1);
|
120
|
-
|
121
|
+
|
121
122
|
/*
|
122
123
|
* call-seq:
|
123
124
|
* buffer.put_bytes(binary_str) -> ByteBuffer
|
@@ -170,7 +171,7 @@ void Init_bson_native()
|
|
170
171
|
* instead on the null terminator), unlike the BSON string serialization.
|
171
172
|
*/
|
172
173
|
rb_define_method(rb_byte_buffer_class, "put_cstring", rb_bson_byte_buffer_put_cstring, 1);
|
173
|
-
|
174
|
+
|
174
175
|
/**
|
175
176
|
* call-seq:
|
176
177
|
* buffer.put_symbol(sym) -> ByteBuffer
|
@@ -188,7 +189,7 @@ void Init_bson_native()
|
|
188
189
|
* indistinguishable from a string with the same value written to the buffer.
|
189
190
|
*/
|
190
191
|
rb_define_method(rb_byte_buffer_class, "put_symbol", rb_bson_byte_buffer_put_symbol, 1);
|
191
|
-
|
192
|
+
|
192
193
|
/*
|
193
194
|
* call-seq:
|
194
195
|
* buffer.put_int32(fixnum) -> ByteBuffer
|
@@ -200,7 +201,7 @@ void Init_bson_native()
|
|
200
201
|
* Returns the modified +self+.
|
201
202
|
*/
|
202
203
|
rb_define_method(rb_byte_buffer_class, "put_int32", rb_bson_byte_buffer_put_int32, 1);
|
203
|
-
|
204
|
+
|
204
205
|
/*
|
205
206
|
* call-seq:
|
206
207
|
* buffer.put_int64(fixnum) -> ByteBuffer
|
@@ -212,7 +213,7 @@ void Init_bson_native()
|
|
212
213
|
* Returns the modified +self+.
|
213
214
|
*/
|
214
215
|
rb_define_method(rb_byte_buffer_class, "put_int64", rb_bson_byte_buffer_put_int64, 1);
|
215
|
-
|
216
|
+
|
216
217
|
/*
|
217
218
|
* call-seq:
|
218
219
|
* buffer.put_double(double) -> ByteBuffer
|
@@ -222,7 +223,7 @@ void Init_bson_native()
|
|
222
223
|
* Returns the modified +self+.
|
223
224
|
*/
|
224
225
|
rb_define_method(rb_byte_buffer_class, "put_double", rb_bson_byte_buffer_put_double, 1);
|
225
|
-
|
226
|
+
|
226
227
|
/*
|
227
228
|
* call-seq:
|
228
229
|
* buffer.put_decimal128(low_64bit, high_64bit) -> ByteBuffer
|
@@ -235,7 +236,7 @@ void Init_bson_native()
|
|
235
236
|
* Returns the modified +self+.
|
236
237
|
*/
|
237
238
|
rb_define_method(rb_byte_buffer_class, "put_decimal128", rb_bson_byte_buffer_put_decimal128, 2);
|
238
|
-
|
239
|
+
|
239
240
|
/*
|
240
241
|
* call-seq:
|
241
242
|
* buffer.put_hash(hash) -> ByteBuffer
|
@@ -245,7 +246,7 @@ void Init_bson_native()
|
|
245
246
|
* Returns the modified +self+.
|
246
247
|
*/
|
247
248
|
rb_define_method(rb_byte_buffer_class, "put_hash", rb_bson_byte_buffer_put_hash, 2);
|
248
|
-
|
249
|
+
|
249
250
|
/*
|
250
251
|
* call-seq:
|
251
252
|
* buffer.put_array(array) -> ByteBuffer
|
@@ -255,7 +256,7 @@ void Init_bson_native()
|
|
255
256
|
* Returns the modified +self+.
|
256
257
|
*/
|
257
258
|
rb_define_method(rb_byte_buffer_class, "put_array", rb_bson_byte_buffer_put_array, 2);
|
258
|
-
|
259
|
+
|
259
260
|
/*
|
260
261
|
* call-seq:
|
261
262
|
* buffer.replace_int32(position, fixnum) -> ByteBuffer
|
@@ -272,7 +273,7 @@ void Init_bson_native()
|
|
272
273
|
* Returns the modified +self+.
|
273
274
|
*/
|
274
275
|
rb_define_method(rb_byte_buffer_class, "replace_int32", rb_bson_byte_buffer_replace_int32, 2);
|
275
|
-
|
276
|
+
|
276
277
|
/*
|
277
278
|
* call-seq:
|
278
279
|
* buffer.rewind! -> ByteBuffer
|
@@ -284,7 +285,7 @@ void Init_bson_native()
|
|
284
285
|
* Returns the modified +self+.
|
285
286
|
*/
|
286
287
|
rb_define_method(rb_byte_buffer_class, "rewind!", rb_bson_byte_buffer_rewind, 0);
|
287
|
-
|
288
|
+
|
288
289
|
/*
|
289
290
|
* call-seq:
|
290
291
|
* buffer.to_s -> String
|
@@ -296,7 +297,7 @@ void Init_bson_native()
|
|
296
297
|
* the buffer itself.
|
297
298
|
*/
|
298
299
|
rb_define_method(rb_byte_buffer_class, "to_s", rb_bson_byte_buffer_to_s, 0);
|
299
|
-
|
300
|
+
|
300
301
|
rb_define_method(rb_bson_object_id_generator_class, "next_object_id", rb_bson_object_id_generator_next, -1);
|
301
302
|
|
302
303
|
// Get the object id machine id and hash it.
|
@@ -309,4 +310,5 @@ void Init_bson_native()
|
|
309
310
|
rb_bson_object_id_counter = FIX2INT(rb_funcall(rb_mKernel, rb_intern("rand"), 1, INT2FIX(0x1000000)));
|
310
311
|
|
311
312
|
rb_bson_registry = rb_const_get(rb_bson_module, rb_intern("Registry"));
|
313
|
+
rb_gc_register_mark_object(rb_bson_registry);
|
312
314
|
}
|
data/ext/bson/read.c
CHANGED
@@ -41,12 +41,12 @@ void pvt_raise_decode_error(volatile VALUE msg) {
|
|
41
41
|
int32_t pvt_validate_length(byte_buffer_t *b)
|
42
42
|
{
|
43
43
|
int32_t length;
|
44
|
-
|
44
|
+
|
45
45
|
ENSURE_BSON_READ(b, 4);
|
46
46
|
memcpy(&length, READ_PTR(b), 4);
|
47
47
|
length = BSON_UINT32_TO_LE(length);
|
48
48
|
|
49
|
-
/* minimum valid length is 4 (byte count) + 1 (terminating byte) */
|
49
|
+
/* minimum valid length is 4 (byte count) + 1 (terminating byte) */
|
50
50
|
if(length >= 5){
|
51
51
|
ENSURE_BSON_READ(b, length);
|
52
52
|
|
@@ -59,7 +59,7 @@ int32_t pvt_validate_length(byte_buffer_t *b)
|
|
59
59
|
else{
|
60
60
|
rb_raise(rb_eRangeError, "Buffer contained invalid length %d at %zu", length, b->read_position);
|
61
61
|
}
|
62
|
-
|
62
|
+
|
63
63
|
return length;
|
64
64
|
}
|
65
65
|
|
@@ -175,13 +175,13 @@ VALUE pvt_get_string(byte_buffer_t *b, const char *data_type)
|
|
175
175
|
}
|
176
176
|
ENSURE_BSON_READ(b, 4 + length);
|
177
177
|
str_ptr = READ_PTR(b) + 4;
|
178
|
-
last_byte = *(READ_PTR(b) + 4 +
|
178
|
+
last_byte = *(READ_PTR(b) + 4 + length - 1);
|
179
179
|
if (last_byte != 0) {
|
180
180
|
pvt_raise_decode_error(rb_sprintf("Last byte of the string is not null: 0x%x", (int) last_byte));
|
181
181
|
}
|
182
182
|
rb_bson_utf8_validate(str_ptr, length - 1, true, data_type);
|
183
183
|
string = rb_enc_str_new(str_ptr, length - 1, rb_utf8_encoding());
|
184
|
-
b->read_position += 4 +
|
184
|
+
b->read_position += 4 + length;
|
185
185
|
return string;
|
186
186
|
}
|
187
187
|
|
@@ -205,7 +205,7 @@ VALUE pvt_get_symbol(byte_buffer_t *b, VALUE rb_buffer, int argc, VALUE *argv)
|
|
205
205
|
klass = rb_funcall(rb_bson_registry, rb_intern("get"), 1, INT2FIX(BSON_TYPE_SYMBOL));
|
206
206
|
value = rb_funcall(klass, rb_intern("from_bson"), 1, rb_buffer);
|
207
207
|
}
|
208
|
-
|
208
|
+
|
209
209
|
RB_GC_GUARD(klass);
|
210
210
|
return value;
|
211
211
|
}
|
@@ -284,7 +284,7 @@ VALUE pvt_get_int64(byte_buffer_t *b, int argc, VALUE *argv)
|
|
284
284
|
memcpy(&i64, READ_PTR(b), 8);
|
285
285
|
b->read_position += 8;
|
286
286
|
num = LL2NUM(BSON_UINT64_FROM_LE(i64));
|
287
|
-
|
287
|
+
|
288
288
|
if (pvt_get_mode_option(argc, argv) == BSON_MODE_BSON) {
|
289
289
|
VALUE klass = rb_funcall(rb_bson_registry,rb_intern("get"),1, INT2FIX(BSON_TYPE_INT64));
|
290
290
|
VALUE value = rb_funcall(klass, rb_intern("new"), 1, num);
|
@@ -293,7 +293,7 @@ VALUE pvt_get_int64(byte_buffer_t *b, int argc, VALUE *argv)
|
|
293
293
|
} else {
|
294
294
|
return num;
|
295
295
|
}
|
296
|
-
|
296
|
+
|
297
297
|
RB_GC_GUARD(num);
|
298
298
|
}
|
299
299
|
|
@@ -353,11 +353,11 @@ VALUE rb_bson_byte_buffer_get_hash(int argc, VALUE *argv, VALUE self){
|
|
353
353
|
rb_hash_aset(doc, field, pvt_read_field(b, self, type, argc, argv));
|
354
354
|
RB_GC_GUARD(field);
|
355
355
|
}
|
356
|
-
|
356
|
+
|
357
357
|
if (READ_PTR(b) - start_ptr != length) {
|
358
358
|
pvt_raise_decode_error(rb_sprintf("Expected to read %d bytes for the hash but read %ld bytes", length, READ_PTR(b) - start_ptr));
|
359
359
|
}
|
360
|
-
|
360
|
+
|
361
361
|
return doc;
|
362
362
|
}
|
363
363
|
|
@@ -379,10 +379,10 @@ VALUE rb_bson_byte_buffer_get_array(int argc, VALUE *argv, VALUE self){
|
|
379
379
|
rb_ary_push(array, pvt_read_field(b, self, type, argc, argv));
|
380
380
|
}
|
381
381
|
RB_GC_GUARD(array);
|
382
|
-
|
382
|
+
|
383
383
|
if (READ_PTR(b) - start_ptr != length) {
|
384
384
|
pvt_raise_decode_error(rb_sprintf("Expected to read %d bytes for the hash but read %ld bytes", length, READ_PTR(b) - start_ptr));
|
385
385
|
}
|
386
|
-
|
386
|
+
|
387
387
|
return array;
|
388
388
|
}
|
data/ext/bson/write.c
CHANGED
@@ -154,8 +154,15 @@ void pvt_put_type_byte(byte_buffer_t *b, VALUE val){
|
|
154
154
|
case T_FLOAT:
|
155
155
|
type_byte = BSON_TYPE_DOUBLE;
|
156
156
|
break;
|
157
|
-
default:{
|
158
|
-
VALUE type
|
157
|
+
default: {
|
158
|
+
VALUE type;
|
159
|
+
VALUE responds = rb_funcall(val, rb_intern("respond_to?"), 1, ID2SYM(rb_intern("bson_type")));
|
160
|
+
if (!RTEST(responds)) {
|
161
|
+
VALUE klass = pvt_const_get_3("BSON", "Error", "UnserializableClass");
|
162
|
+
VALUE val_str = rb_funcall(val, rb_intern("to_s"), 0);
|
163
|
+
rb_raise(klass, "Value does not define its BSON serialized type: %s", RSTRING_PTR(val_str));
|
164
|
+
}
|
165
|
+
type = rb_funcall(val, rb_intern("bson_type"), 0);
|
159
166
|
type_byte = *RSTRING_PTR(type);
|
160
167
|
RB_GC_GUARD(type);
|
161
168
|
break;
|
@@ -627,7 +634,7 @@ VALUE rb_bson_byte_buffer_put_array(VALUE self, VALUE array, VALUE validating_ke
|
|
627
634
|
|
628
635
|
for(int32_t index=0; index < RARRAY_LEN(array); index++, array_element++){
|
629
636
|
pvt_put_type_byte(b, *array_element);
|
630
|
-
pvt_put_array_index(b,index);
|
637
|
+
pvt_put_array_index(b, index);
|
631
638
|
pvt_put_field(b, self, *array_element, validating_keys);
|
632
639
|
}
|
633
640
|
pvt_put_byte(b, 0);
|
data/lib/bson/array.rb
CHANGED
@@ -47,6 +47,9 @@ module BSON
|
|
47
47
|
position = buffer.length
|
48
48
|
buffer.put_int32(0)
|
49
49
|
each_with_index do |value, index|
|
50
|
+
unless value.respond_to?(:bson_type)
|
51
|
+
raise Error::UnserializableClass, "Array element at position #{index} does not define its BSON serialized type: #{value}"
|
52
|
+
end
|
50
53
|
buffer.put_byte(value.bson_type)
|
51
54
|
buffer.put_cstring(index.to_s)
|
52
55
|
value.to_bson(buffer, validating_keys)
|
data/lib/bson/error.rb
CHANGED
@@ -17,5 +17,11 @@ module BSON
|
|
17
17
|
# Exception raised when BSON decoding fails.
|
18
18
|
class BSONDecodeError < Error
|
19
19
|
end
|
20
|
+
|
21
|
+
# Exception raised when serializing an Array or Hash to BSON and an
|
22
|
+
# array or hash element is of a class that does not define how to serialize
|
23
|
+
# itself to BSON.
|
24
|
+
class UnserializableClass < Error
|
25
|
+
end
|
20
26
|
end
|
21
27
|
end
|
data/lib/bson/hash.rb
CHANGED
@@ -44,6 +44,9 @@ module BSON
|
|
44
44
|
position = buffer.length
|
45
45
|
buffer.put_int32(0)
|
46
46
|
each do |field, value|
|
47
|
+
unless value.respond_to?(:bson_type)
|
48
|
+
raise Error::UnserializableClass, "Hash value for key '#{field}' does not define its BSON serialized type: #{value}"
|
49
|
+
end
|
47
50
|
buffer.put_byte(value.bson_type)
|
48
51
|
key = field.to_bson_key(validating_keys)
|
49
52
|
begin
|
data/lib/bson/regexp.rb
CHANGED
@@ -165,7 +165,13 @@ module BSON
|
|
165
165
|
#
|
166
166
|
# @since 3.1.0
|
167
167
|
def respond_to?(method, include_private = false)
|
168
|
-
|
168
|
+
if defined?(@pattern)
|
169
|
+
compile.respond_to?(method, include_private) || super
|
170
|
+
else
|
171
|
+
# YAML calls #respond_to? during deserialization, before the object
|
172
|
+
# is initialized.
|
173
|
+
super
|
174
|
+
end
|
169
175
|
end
|
170
176
|
|
171
177
|
# Encode the Raw Regexp object to BSON.
|
data/lib/bson/version.rb
CHANGED
Binary file
|
data/spec/bson/array_spec.rb
CHANGED
@@ -132,6 +132,23 @@ describe Array do
|
|
132
132
|
end
|
133
133
|
end
|
134
134
|
end
|
135
|
+
|
136
|
+
context 'when array contains value of an unserializable class' do
|
137
|
+
class ArraySpecUnserializableClass
|
138
|
+
end
|
139
|
+
|
140
|
+
let(:obj) do
|
141
|
+
[ArraySpecUnserializableClass.new]
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'raises UnserializableClass' do
|
145
|
+
lambda do
|
146
|
+
obj.to_bson
|
147
|
+
end.should raise_error(BSON::Error::UnserializableClass,
|
148
|
+
# C extension does not provide element position in the exception message.
|
149
|
+
/(Array element at position 0|Value) does not define its BSON serialized type:.*ArraySpecUnserializableClass/)
|
150
|
+
end
|
151
|
+
end
|
135
152
|
end
|
136
153
|
|
137
154
|
describe "#to_bson_normalized_value" do
|
data/spec/bson/hash_spec.rb
CHANGED
@@ -227,6 +227,23 @@ describe Hash do
|
|
227
227
|
end
|
228
228
|
end
|
229
229
|
end
|
230
|
+
|
231
|
+
context 'when hash contains value of an unserializable class' do
|
232
|
+
class HashSpecUnserializableClass
|
233
|
+
end
|
234
|
+
|
235
|
+
let(:obj) do
|
236
|
+
{foo: HashSpecUnserializableClass.new}
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'raises UnserializableClass' do
|
240
|
+
lambda do
|
241
|
+
obj.to_bson
|
242
|
+
end.should raise_error(BSON::Error::UnserializableClass,
|
243
|
+
# C extension does not provide hash key in the exception message.
|
244
|
+
/(Hash value for key 'foo'|Value) does not define its BSON serialized type:.*HashSpecUnserializableClass/)
|
245
|
+
end
|
246
|
+
end
|
230
247
|
end
|
231
248
|
|
232
249
|
describe '#to_bson' do
|
data/spec/bson/raw_spec.rb
CHANGED
@@ -580,4 +580,15 @@ describe Regexp::Raw do
|
|
580
580
|
end
|
581
581
|
end
|
582
582
|
end
|
583
|
-
|
583
|
+
|
584
|
+
describe 'yaml loading' do
|
585
|
+
let(:regexp) { described_class.new('hello.world', 's') }
|
586
|
+
|
587
|
+
it 'round-trips' do
|
588
|
+
actual = YAML.load(regexp.to_yaml)
|
589
|
+
actual.pattern.should == 'hello.world'
|
590
|
+
actual.options.should == 's'
|
591
|
+
actual.compile.should =~ "hello\nworld"
|
592
|
+
end
|
593
|
+
end
|
594
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -60,4 +60,15 @@ RSpec.configure do |config|
|
|
60
60
|
config.expect_with :rspec do |c|
|
61
61
|
c.syntax = [:should, :expect]
|
62
62
|
end
|
63
|
+
|
64
|
+
# To ensure that calling GC.compact does not produce unexpected behavior,
|
65
|
+
# randomly call GC.compact after a small percentage of tests in the suite.
|
66
|
+
# This behavior is only enabled when the COMPACT environment variable is true.
|
67
|
+
if SpecConfig.instance.compact?
|
68
|
+
config.after do
|
69
|
+
if rand < SpecConfig::COMPACTION_CHANCE
|
70
|
+
GC.compact
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
63
74
|
end
|
data/spec/support/spec_config.rb
CHANGED
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.
|
4
|
+
version: 4.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Brock
|
@@ -11,8 +11,29 @@ authors:
|
|
11
11
|
- Gary Murakami
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
|
-
cert_chain:
|
15
|
-
|
14
|
+
cert_chain:
|
15
|
+
- |
|
16
|
+
-----BEGIN CERTIFICATE-----
|
17
|
+
MIIDRDCCAiygAwIBAgIBATANBgkqhkiG9w0BAQsFADAmMSQwIgYDVQQDDBtkcml2
|
18
|
+
ZXItcnVieS9EQz0xMGdlbi9EQz1jb20wHhcNMjAwMTIzMTkzNjAxWhcNMjEwMTIy
|
19
|
+
MTkzNjAxWjAmMSQwIgYDVQQDDBtkcml2ZXItcnVieS9EQz0xMGdlbi9EQz1jb20w
|
20
|
+
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDRXUgGvH0ZtWwDPc2umdHw
|
21
|
+
B+INNm6jNTRp8PMyUKxPzxaxX2OiBQk9gLC3zsK9ZmlZu4lNfpHVSCEPoiP/fhPg
|
22
|
+
Kyfq2xld3Qz0Pki5d5i0/r14343MTKiNiFulLlbbdlN0cXeEFNJHUycZnD2LOXwz
|
23
|
+
egYGHOl14FI8t5visIWtqRnLXXIlDsBHzmeEZjUZRGSgjC0R3RT/I+Fk5yUhn1w4
|
24
|
+
rqFyAiW+cjjzmT7mmqT0jV6fd0JFHbKnSgt9iPijKSimBgUOsorHwOTMlTzwsy0d
|
25
|
+
ZT+al1RiT5zqlAJLxFHwmoYOxD/bSNtKsYl60ek0hK2mISBVy9BBmLvCgHDx5uSp
|
26
|
+
AgMBAAGjfTB7MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBRbd1mx
|
27
|
+
fvSaVIwKI+tnEAYDW/B81zAgBgNVHREEGTAXgRVkcml2ZXItcnVieUAxMGdlbi5j
|
28
|
+
b20wIAYDVR0SBBkwF4EVZHJpdmVyLXJ1YnlAMTBnZW4uY29tMA0GCSqGSIb3DQEB
|
29
|
+
CwUAA4IBAQBfX4dwxG5PhtxES/LDEOaZIZXyaX6CKe367zhW+HxWbSOXMQJFkIQj
|
30
|
+
m7tzT+sDFJXyiOv5cPtfpUam5pTiryzRw5HD6oxlPIt5vO15EJ69v++3m7shMLbw
|
31
|
+
amZOajKXmu2ZGZfhOtj7bOTwmOj1AnWLKeOQIR3STvvfZCD+6dt1XenW7CdjCsxE
|
32
|
+
ifervPjLFqFPsMOgaxikhgPK6bRtszrQhJSYlifKKzxbX1hYAsmGL7IxjubFSV5r
|
33
|
+
gpvfPNWMwyBDlHaNS3GfO6cRRxBOvEG05GUCsvtTY4Bpe8yjE64wg1ymb47LMOnv
|
34
|
+
Qb1lGORmf/opg45mluKUYl7pQNZHD0d3
|
35
|
+
-----END CERTIFICATE-----
|
36
|
+
date: 2020-10-13 00:00:00.000000000 Z
|
16
37
|
dependencies: []
|
17
38
|
description: A fully featured BSON specification implementation in Ruby
|
18
39
|
email:
|
@@ -78,6 +99,7 @@ files:
|
|
78
99
|
- lib/bson/true_class.rb
|
79
100
|
- lib/bson/undefined.rb
|
80
101
|
- lib/bson/version.rb
|
102
|
+
- lib/bson_native.bundle
|
81
103
|
- spec/bson/array_spec.rb
|
82
104
|
- spec/bson/binary_spec.rb
|
83
105
|
- spec/bson/binary_uuid_spec.rb
|
@@ -212,118 +234,119 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
234
|
- !ruby/object:Gem::Version
|
213
235
|
version: 1.3.6
|
214
236
|
requirements: []
|
215
|
-
|
237
|
+
rubyforge_project:
|
238
|
+
rubygems_version: 2.7.6.2
|
216
239
|
signing_key:
|
217
240
|
specification_version: 4
|
218
241
|
summary: Ruby implementation of the BSON specification
|
219
242
|
test_files:
|
220
|
-
- spec/
|
221
|
-
- spec/
|
222
|
-
- spec/runners/common_driver.rb
|
223
|
-
- spec/bson/max_key_spec.rb
|
224
|
-
- spec/bson/byte_buffer_spec.rb
|
225
|
-
- spec/bson/ext_json_parse_spec.rb
|
226
|
-
- spec/bson/byte_buffer_read_spec.rb
|
227
|
-
- spec/bson/decimal128_spec.rb
|
228
|
-
- spec/bson/date_spec.rb
|
229
|
-
- spec/bson/object_spec.rb
|
230
|
-
- spec/bson/int64_spec.rb
|
231
|
-
- spec/bson/int32_spec.rb
|
232
|
-
- spec/bson/object_id_spec.rb
|
233
|
-
- spec/bson/hash_spec.rb
|
234
|
-
- spec/bson/string_spec.rb
|
235
|
-
- spec/bson/boolean_spec.rb
|
236
|
-
- spec/bson/timestamp_spec.rb
|
237
|
-
- spec/bson/open_struct_spec.rb
|
238
|
-
- spec/bson/config_spec.rb
|
239
|
-
- spec/bson/nil_class_spec.rb
|
240
|
-
- spec/bson/regexp_spec.rb
|
241
|
-
- spec/bson/time_with_zone_spec.rb
|
242
|
-
- spec/bson/code_spec.rb
|
243
|
-
- spec/bson/false_class_spec.rb
|
244
|
-
- spec/bson/raw_spec.rb
|
245
|
-
- spec/bson/binary_spec.rb
|
246
|
-
- spec/bson/array_spec.rb
|
247
|
-
- spec/bson/code_with_scope_spec.rb
|
248
|
-
- spec/bson/symbol_spec.rb
|
249
|
-
- spec/bson/float_spec.rb
|
250
|
-
- spec/bson/symbol_raw_spec.rb
|
251
|
-
- spec/bson/true_class_spec.rb
|
252
|
-
- spec/bson/integer_spec.rb
|
253
|
-
- spec/bson/binary_uuid_spec.rb
|
254
|
-
- spec/bson/time_spec.rb
|
255
|
-
- spec/bson/json_spec.rb
|
256
|
-
- spec/bson/date_time_spec.rb
|
257
|
-
- spec/bson/document_spec.rb
|
258
|
-
- spec/bson/byte_buffer_write_spec.rb
|
259
|
-
- spec/bson/min_key_spec.rb
|
260
|
-
- spec/bson/undefined_spec.rb
|
261
|
-
- spec/bson/registry_spec.rb
|
262
|
-
- spec/support/shared_examples.rb
|
263
|
-
- spec/support/spec_config.rb
|
264
|
-
- spec/support/utils.rb
|
265
|
-
- spec/spec_tests/data/corpus_legacy/code.json
|
266
|
-
- spec/spec_tests/data/corpus_legacy/code_w_scope.json
|
267
|
-
- spec/spec_tests/data/corpus_legacy/failures/symbol.json
|
268
|
-
- spec/spec_tests/data/corpus_legacy/failures/datetime.json
|
269
|
-
- spec/spec_tests/data/corpus_legacy/failures/int64.json
|
270
|
-
- spec/spec_tests/data/corpus_legacy/failures/dbpointer.json
|
271
|
-
- spec/spec_tests/data/corpus_legacy/null.json
|
272
|
-
- spec/spec_tests/data/corpus_legacy/boolean.json
|
273
|
-
- spec/spec_tests/data/corpus_legacy/oid.json
|
274
|
-
- spec/spec_tests/data/corpus_legacy/regex.json
|
275
|
-
- spec/spec_tests/data/corpus_legacy/array.json
|
276
|
-
- spec/spec_tests/data/corpus_legacy/document.json
|
277
|
-
- spec/spec_tests/data/corpus_legacy/undefined.json
|
278
|
-
- spec/spec_tests/data/corpus_legacy/binary.json
|
279
|
-
- spec/spec_tests/data/corpus_legacy/minkey.json
|
280
|
-
- spec/spec_tests/data/corpus_legacy/maxkey.json
|
281
|
-
- spec/spec_tests/data/corpus_legacy/int32.json
|
282
|
-
- spec/spec_tests/data/corpus_legacy/timestamp.json
|
283
|
-
- spec/spec_tests/data/corpus_legacy/top.json
|
284
|
-
- spec/spec_tests/data/corpus_legacy/string.json
|
285
|
-
- spec/spec_tests/data/corpus_legacy/double.json
|
286
|
-
- spec/spec_tests/data/corpus/code.json
|
287
|
-
- spec/spec_tests/data/corpus/code_w_scope.json
|
288
|
-
- spec/spec_tests/data/corpus/decimal128-1.json
|
289
|
-
- spec/spec_tests/data/corpus/null.json
|
290
|
-
- spec/spec_tests/data/corpus/multi-type.json
|
291
|
-
- spec/spec_tests/data/corpus/boolean.json
|
292
|
-
- spec/spec_tests/data/corpus/symbol.json
|
293
|
-
- spec/spec_tests/data/corpus/datetime.json
|
294
|
-
- spec/spec_tests/data/corpus/oid.json
|
295
|
-
- spec/spec_tests/data/corpus/regex.json
|
296
|
-
- spec/spec_tests/data/corpus/int64.json
|
297
|
-
- spec/spec_tests/data/corpus/decimal128-7.json
|
243
|
+
- spec/spec_tests/common_driver_spec.rb
|
244
|
+
- spec/spec_tests/corpus_legacy_spec.rb
|
298
245
|
- spec/spec_tests/data/corpus/array.json
|
299
|
-
- spec/spec_tests/data/corpus/decimal128-3.json
|
300
|
-
- spec/spec_tests/data/corpus/decimal128-5.json
|
301
246
|
- spec/spec_tests/data/corpus/document.json
|
302
|
-
- spec/spec_tests/data/corpus/
|
303
|
-
- spec/spec_tests/data/corpus/
|
247
|
+
- spec/spec_tests/data/corpus/decimal128-7.json
|
248
|
+
- spec/spec_tests/data/corpus/decimal128-3.json
|
249
|
+
- spec/spec_tests/data/corpus/maxkey.json
|
250
|
+
- spec/spec_tests/data/corpus/code.json
|
304
251
|
- spec/spec_tests/data/corpus/dbpointer.json
|
252
|
+
- spec/spec_tests/data/corpus/int32.json
|
253
|
+
- spec/spec_tests/data/corpus/README.md
|
254
|
+
- spec/spec_tests/data/corpus/decimal128-5.json
|
305
255
|
- spec/spec_tests/data/corpus/decimal128-4.json
|
306
|
-
- spec/spec_tests/data/corpus/
|
256
|
+
- spec/spec_tests/data/corpus/decimal128-2.json
|
257
|
+
- spec/spec_tests/data/corpus/double.json
|
258
|
+
- spec/spec_tests/data/corpus/code_w_scope.json
|
259
|
+
- spec/spec_tests/data/corpus/binary.json
|
260
|
+
- spec/spec_tests/data/corpus/oid.json
|
261
|
+
- spec/spec_tests/data/corpus/null.json
|
307
262
|
- spec/spec_tests/data/corpus/decimal128-6.json
|
263
|
+
- spec/spec_tests/data/corpus/int64.json
|
308
264
|
- spec/spec_tests/data/corpus/dbref.json
|
309
|
-
- spec/spec_tests/data/corpus/
|
265
|
+
- spec/spec_tests/data/corpus/regex.json
|
310
266
|
- spec/spec_tests/data/corpus/minkey.json
|
311
|
-
- spec/spec_tests/data/corpus/
|
312
|
-
- spec/spec_tests/data/corpus/maxkey.json
|
313
|
-
- spec/spec_tests/data/corpus/int32.json
|
314
|
-
- spec/spec_tests/data/corpus/timestamp.json
|
267
|
+
- spec/spec_tests/data/corpus/multi-type.json
|
315
268
|
- spec/spec_tests/data/corpus/top.json
|
269
|
+
- spec/spec_tests/data/corpus/symbol.json
|
270
|
+
- spec/spec_tests/data/corpus/multi-type-deprecated.json
|
271
|
+
- spec/spec_tests/data/corpus/undefined.json
|
272
|
+
- spec/spec_tests/data/corpus/datetime.json
|
316
273
|
- spec/spec_tests/data/corpus/string.json
|
317
|
-
- spec/spec_tests/data/corpus/
|
318
|
-
- spec/spec_tests/data/
|
274
|
+
- spec/spec_tests/data/corpus/boolean.json
|
275
|
+
- spec/spec_tests/data/corpus/timestamp.json
|
276
|
+
- spec/spec_tests/data/corpus/decimal128-1.json
|
319
277
|
- spec/spec_tests/data/decimal128/decimal128-7.json
|
320
278
|
- spec/spec_tests/data/decimal128/decimal128-3.json
|
321
279
|
- spec/spec_tests/data/decimal128/decimal128-5.json
|
322
280
|
- spec/spec_tests/data/decimal128/decimal128-4.json
|
323
|
-
- spec/spec_tests/data/decimal128/decimal128-6.json
|
324
281
|
- spec/spec_tests/data/decimal128/decimal128-2.json
|
325
|
-
- spec/spec_tests/
|
282
|
+
- spec/spec_tests/data/decimal128/decimal128-6.json
|
283
|
+
- spec/spec_tests/data/decimal128/decimal128-1.json
|
284
|
+
- spec/spec_tests/data/corpus_legacy/array.json
|
285
|
+
- spec/spec_tests/data/corpus_legacy/document.json
|
286
|
+
- spec/spec_tests/data/corpus_legacy/maxkey.json
|
287
|
+
- spec/spec_tests/data/corpus_legacy/code.json
|
288
|
+
- spec/spec_tests/data/corpus_legacy/int32.json
|
289
|
+
- spec/spec_tests/data/corpus_legacy/double.json
|
290
|
+
- spec/spec_tests/data/corpus_legacy/code_w_scope.json
|
291
|
+
- spec/spec_tests/data/corpus_legacy/binary.json
|
292
|
+
- spec/spec_tests/data/corpus_legacy/oid.json
|
293
|
+
- spec/spec_tests/data/corpus_legacy/null.json
|
294
|
+
- spec/spec_tests/data/corpus_legacy/regex.json
|
295
|
+
- spec/spec_tests/data/corpus_legacy/minkey.json
|
296
|
+
- spec/spec_tests/data/corpus_legacy/top.json
|
297
|
+
- spec/spec_tests/data/corpus_legacy/failures/dbpointer.json
|
298
|
+
- spec/spec_tests/data/corpus_legacy/failures/int64.json
|
299
|
+
- spec/spec_tests/data/corpus_legacy/failures/symbol.json
|
300
|
+
- spec/spec_tests/data/corpus_legacy/failures/datetime.json
|
301
|
+
- spec/spec_tests/data/corpus_legacy/undefined.json
|
302
|
+
- spec/spec_tests/data/corpus_legacy/string.json
|
303
|
+
- spec/spec_tests/data/corpus_legacy/boolean.json
|
304
|
+
- spec/spec_tests/data/corpus_legacy/timestamp.json
|
326
305
|
- spec/spec_tests/corpus_spec.rb
|
327
|
-
- spec/
|
328
|
-
- spec/
|
306
|
+
- spec/runners/corpus.rb
|
307
|
+
- spec/runners/corpus_legacy.rb
|
308
|
+
- spec/runners/common_driver.rb
|
329
309
|
- spec/spec_helper.rb
|
310
|
+
- spec/support/spec_config.rb
|
311
|
+
- spec/support/shared_examples.rb
|
312
|
+
- spec/support/utils.rb
|
313
|
+
- spec/bson/ext_json_parse_spec.rb
|
314
|
+
- spec/bson/object_spec.rb
|
315
|
+
- spec/bson/json_spec.rb
|
316
|
+
- spec/bson/true_class_spec.rb
|
317
|
+
- spec/bson/byte_buffer_read_spec.rb
|
318
|
+
- spec/bson/config_spec.rb
|
319
|
+
- spec/bson/int32_spec.rb
|
320
|
+
- spec/bson/regexp_spec.rb
|
321
|
+
- spec/bson/symbol_raw_spec.rb
|
322
|
+
- spec/bson/open_struct_spec.rb
|
323
|
+
- spec/bson/document_spec.rb
|
324
|
+
- spec/bson/min_key_spec.rb
|
325
|
+
- spec/bson/false_class_spec.rb
|
326
|
+
- spec/bson/code_spec.rb
|
327
|
+
- spec/bson/symbol_spec.rb
|
328
|
+
- spec/bson/object_id_spec.rb
|
329
|
+
- spec/bson/decimal128_spec.rb
|
330
|
+
- spec/bson/registry_spec.rb
|
331
|
+
- spec/bson/time_spec.rb
|
332
|
+
- spec/bson/boolean_spec.rb
|
333
|
+
- spec/bson/byte_buffer_spec.rb
|
334
|
+
- spec/bson/hash_spec.rb
|
335
|
+
- spec/bson/undefined_spec.rb
|
336
|
+
- spec/bson/raw_spec.rb
|
337
|
+
- spec/bson/string_spec.rb
|
338
|
+
- spec/bson/timestamp_spec.rb
|
339
|
+
- spec/bson/date_time_spec.rb
|
340
|
+
- spec/bson/max_key_spec.rb
|
341
|
+
- spec/bson/int64_spec.rb
|
342
|
+
- spec/bson/byte_buffer_write_spec.rb
|
343
|
+
- spec/bson/date_spec.rb
|
344
|
+
- spec/bson/binary_spec.rb
|
345
|
+
- spec/bson/code_with_scope_spec.rb
|
346
|
+
- spec/bson/integer_spec.rb
|
347
|
+
- spec/bson/binary_uuid_spec.rb
|
348
|
+
- spec/bson/nil_class_spec.rb
|
349
|
+
- spec/bson/array_spec.rb
|
350
|
+
- spec/bson/time_with_zone_spec.rb
|
351
|
+
- spec/bson/float_spec.rb
|
352
|
+
- spec/bson_spec.rb
|
metadata.gz.sig
ADDED
Binary file
|