bson 4.8.1 → 4.9.3
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 +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +18 -6
- data/ext/bson/bson-endian.h +1 -1
- data/ext/bson/bson-native.h +1 -1
- data/ext/bson/bytebuf.c +1 -1
- data/ext/bson/endian.c +1 -1
- data/ext/bson/init.c +24 -22
- data/ext/bson/read.c +67 -19
- data/ext/bson/util.c +1 -1
- data/ext/bson/write.c +1 -1
- data/lib/bson.rb +1 -1
- data/lib/bson/active_support.rb +1 -1
- data/lib/bson/array.rb +14 -3
- data/lib/bson/binary.rb +1 -1
- data/lib/bson/boolean.rb +9 -2
- data/lib/bson/code.rb +1 -1
- data/lib/bson/code_with_scope.rb +16 -3
- data/lib/bson/config.rb +1 -1
- data/lib/bson/date.rb +1 -1
- data/lib/bson/date_time.rb +1 -1
- data/lib/bson/db_pointer.rb +7 -1
- data/lib/bson/decimal128.rb +1 -1
- data/lib/bson/decimal128/builder.rb +1 -1
- data/lib/bson/document.rb +1 -1
- data/lib/bson/environment.rb +2 -1
- data/lib/bson/error.rb +4 -0
- data/lib/bson/ext_json.rb +3 -3
- data/lib/bson/false_class.rb +1 -1
- data/lib/bson/float.rb +1 -1
- data/lib/bson/hash.rb +7 -2
- data/lib/bson/int32.rb +1 -1
- data/lib/bson/int64.rb +1 -1
- data/lib/bson/integer.rb +1 -1
- data/lib/bson/json.rb +1 -1
- data/lib/bson/max_key.rb +1 -1
- data/lib/bson/min_key.rb +1 -1
- data/lib/bson/nil_class.rb +1 -1
- data/lib/bson/object.rb +1 -1
- data/lib/bson/object_id.rb +1 -1
- data/lib/bson/open_struct.rb +1 -1
- data/lib/bson/regexp.rb +8 -2
- data/lib/bson/registry.rb +1 -1
- data/lib/bson/specialized.rb +1 -1
- data/lib/bson/string.rb +1 -1
- data/lib/bson/symbol.rb +1 -1
- data/lib/bson/time.rb +1 -1
- data/lib/bson/time_with_zone.rb +1 -1
- data/lib/bson/timestamp.rb +1 -1
- data/lib/bson/true_class.rb +1 -1
- data/lib/bson/undefined.rb +1 -1
- data/lib/bson/version.rb +2 -2
- data/spec/bson/array_spec.rb +1 -1
- data/spec/bson/binary_spec.rb +1 -1
- data/spec/bson/binary_uuid_spec.rb +1 -1
- data/spec/bson/boolean_spec.rb +1 -1
- data/spec/bson/code_spec.rb +1 -1
- data/spec/bson/code_with_scope_spec.rb +1 -1
- data/spec/bson/date_spec.rb +1 -1
- data/spec/bson/date_time_spec.rb +1 -1
- data/spec/bson/decimal128_spec.rb +1 -1
- data/spec/bson/document_spec.rb +1 -1
- data/spec/bson/ext_json_parse_spec.rb +34 -2
- data/spec/bson/false_class_spec.rb +1 -1
- data/spec/bson/float_spec.rb +1 -1
- data/spec/bson/hash_spec.rb +1 -1
- data/spec/bson/int32_spec.rb +1 -1
- data/spec/bson/int64_spec.rb +1 -1
- data/spec/bson/integer_spec.rb +1 -1
- data/spec/bson/json_spec.rb +1 -1
- data/spec/bson/max_key_spec.rb +1 -1
- data/spec/bson/min_key_spec.rb +1 -1
- data/spec/bson/nil_class_spec.rb +1 -1
- data/spec/bson/object_id_spec.rb +1 -1
- data/spec/bson/object_spec.rb +1 -1
- data/spec/bson/open_struct_spec.rb +1 -1
- data/spec/bson/raw_spec.rb +12 -1
- data/spec/bson/regexp_spec.rb +1 -1
- data/spec/bson/registry_spec.rb +1 -1
- data/spec/bson/string_spec.rb +1 -1
- data/spec/bson/symbol_spec.rb +1 -1
- data/spec/bson/time_spec.rb +1 -1
- data/spec/bson/time_with_zone_spec.rb +1 -1
- data/spec/bson/timestamp_spec.rb +1 -1
- data/spec/bson/true_class_spec.rb +1 -1
- data/spec/bson/undefined_spec.rb +1 -1
- data/spec/bson_spec.rb +1 -1
- data/spec/runners/common_driver.rb +1 -1
- data/spec/runners/corpus.rb +13 -10
- data/spec/runners/corpus_legacy.rb +1 -1
- data/spec/spec_helper.rb +12 -1
- data/spec/spec_tests/data/corpus/top.json +0 -4
- data/spec/support/shared_examples.rb +1 -1
- data/spec/support/spec_config.rb +6 -0
- metadata +92 -94
- metadata.gz.sig +0 -0
data/ext/bson/util.c
CHANGED
data/ext/bson/write.c
CHANGED
data/lib/bson.rb
CHANGED
data/lib/bson/active_support.rb
CHANGED
data/lib/bson/array.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -119,10 +119,21 @@ module BSON
|
|
119
119
|
buffer.get_array(**options)
|
120
120
|
else
|
121
121
|
array = new
|
122
|
-
buffer.
|
122
|
+
start_position = buffer.read_position
|
123
|
+
expected_byte_size = buffer.get_int32
|
123
124
|
while (type = buffer.get_byte) != NULL_BYTE
|
124
125
|
buffer.get_cstring
|
125
|
-
|
126
|
+
cls = BSON::Registry.get(type)
|
127
|
+
value = if options.empty?
|
128
|
+
cls.from_bson(buffer)
|
129
|
+
else
|
130
|
+
cls.from_bson(buffer, **options)
|
131
|
+
end
|
132
|
+
array << value
|
133
|
+
end
|
134
|
+
actual_byte_size = buffer.read_position - start_position
|
135
|
+
if actual_byte_size != expected_byte_size
|
136
|
+
raise Error::BSONDecodeError, "Expected array to take #{expected_byte_size} bytes but it took #{actual_byte_size} bytes"
|
126
137
|
end
|
127
138
|
array
|
128
139
|
end
|
data/lib/bson/binary.rb
CHANGED
data/lib/bson/boolean.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -39,7 +39,14 @@ module BSON
|
|
39
39
|
#
|
40
40
|
# @since 2.0.0
|
41
41
|
def self.from_bson(buffer, **options)
|
42
|
-
buffer.get_byte
|
42
|
+
case v = buffer.get_byte
|
43
|
+
when TrueClass::TRUE_BYTE
|
44
|
+
true
|
45
|
+
when FalseClass::FALSE_BYTE
|
46
|
+
false
|
47
|
+
else
|
48
|
+
raise Error::BSONDecodeError, "Invalid boolean byte value: #{v}"
|
49
|
+
end
|
43
50
|
end
|
44
51
|
|
45
52
|
# Register this type when the module is loaded.
|
data/lib/bson/code.rb
CHANGED
data/lib/bson/code_with_scope.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -119,8 +119,21 @@ module BSON
|
|
119
119
|
#
|
120
120
|
# @since 2.0.0
|
121
121
|
def self.from_bson(buffer, **options)
|
122
|
-
|
123
|
-
|
122
|
+
# Code with scope has a length (?) field which is not needed for
|
123
|
+
# decoding, but spec tests want this field validated.
|
124
|
+
start_position = buffer.read_position
|
125
|
+
length = buffer.get_int32
|
126
|
+
javascript = buffer.get_string
|
127
|
+
scope = if options.empty?
|
128
|
+
::Hash.from_bson(buffer)
|
129
|
+
else
|
130
|
+
::Hash.from_bson(buffer, **options)
|
131
|
+
end
|
132
|
+
read_bytes = buffer.read_position - start_position
|
133
|
+
if read_bytes != length
|
134
|
+
raise Error::BSONDecodeError, "CodeWithScope invalid: claimed length #{length}, actual length #{read_bytes}"
|
135
|
+
end
|
136
|
+
new(javascript, scope)
|
124
137
|
end
|
125
138
|
|
126
139
|
# Register this type when the module is loaded.
|
data/lib/bson/config.rb
CHANGED
data/lib/bson/date.rb
CHANGED
data/lib/bson/date_time.rb
CHANGED
data/lib/bson/db_pointer.rb
CHANGED
@@ -95,7 +95,13 @@ module BSON
|
|
95
95
|
#
|
96
96
|
# @see http://bsonspec.org/#/specification
|
97
97
|
def self.from_bson(buffer, **options)
|
98
|
-
|
98
|
+
ref = buffer.get_string
|
99
|
+
id = if options.empty?
|
100
|
+
ObjectId.from_bson(buffer)
|
101
|
+
else
|
102
|
+
ObjectId.from_bson(buffer, **options)
|
103
|
+
end
|
104
|
+
new(ref, id)
|
99
105
|
end
|
100
106
|
|
101
107
|
# Register this type when the module is loaded.
|
data/lib/bson/decimal128.rb
CHANGED
data/lib/bson/document.rb
CHANGED
data/lib/bson/environment.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -41,6 +41,7 @@ module BSON
|
|
41
41
|
# @return [ true, false ] If the Ruby version is 1.9.
|
42
42
|
#
|
43
43
|
# @since 4.2.0
|
44
|
+
# @deprecated
|
44
45
|
def ruby_1_9?
|
45
46
|
@ruby_1_9 ||= RUBY_VERSION < '2.0.0'
|
46
47
|
end
|
data/lib/bson/error.rb
CHANGED
data/lib/bson/ext_json.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2019 MongoDB Inc.
|
1
|
+
# Copyright (C) 2019-2020 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -251,13 +251,13 @@ module BSON
|
|
251
251
|
when '$date'
|
252
252
|
case value
|
253
253
|
when String
|
254
|
-
::Time.parse(value)
|
254
|
+
::Time.parse(value).utc
|
255
255
|
when Hash
|
256
256
|
unless value.keys.sort == %w($numberLong)
|
257
257
|
raise Error::ExtJSONParseError, "Invalid value for $date: #{value}"
|
258
258
|
end
|
259
259
|
sec, msec = value.values.first.to_i.divmod(1000)
|
260
|
-
::Time.at(sec, msec*1000)
|
260
|
+
::Time.at(sec, msec*1000).utc
|
261
261
|
else
|
262
262
|
raise Error::ExtJSONParseError, "Invalid value for $date: #{value}"
|
263
263
|
end
|
data/lib/bson/false_class.rb
CHANGED
data/lib/bson/float.rb
CHANGED
data/lib/bson/hash.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -108,7 +108,8 @@ module BSON
|
|
108
108
|
buffer.get_hash(**options)
|
109
109
|
else
|
110
110
|
hash = Document.allocate
|
111
|
-
|
111
|
+
start_position = buffer.read_position
|
112
|
+
expected_byte_size = buffer.get_int32
|
112
113
|
while (type = buffer.get_byte) != NULL_BYTE
|
113
114
|
field = buffer.get_cstring
|
114
115
|
cls = BSON::Registry.get(type, field)
|
@@ -121,6 +122,10 @@ module BSON
|
|
121
122
|
end
|
122
123
|
hash.store(field, value)
|
123
124
|
end
|
125
|
+
actual_byte_size = buffer.read_position - start_position
|
126
|
+
if actual_byte_size != expected_byte_size
|
127
|
+
raise Error::BSONDecodeError, "Expected hash to take #{expected_byte_size} bytes but it took #{actual_byte_size} bytes"
|
128
|
+
end
|
124
129
|
hash
|
125
130
|
end
|
126
131
|
end
|
data/lib/bson/int32.rb
CHANGED
data/lib/bson/int64.rb
CHANGED
data/lib/bson/integer.rb
CHANGED
data/lib/bson/json.rb
CHANGED
data/lib/bson/max_key.rb
CHANGED
data/lib/bson/min_key.rb
CHANGED
data/lib/bson/nil_class.rb
CHANGED
data/lib/bson/object.rb
CHANGED
data/lib/bson/object_id.rb
CHANGED
data/lib/bson/open_struct.rb
CHANGED
data/lib/bson/regexp.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -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/registry.rb
CHANGED
data/lib/bson/specialized.rb
CHANGED
data/lib/bson/string.rb
CHANGED
data/lib/bson/symbol.rb
CHANGED
data/lib/bson/time.rb
CHANGED
data/lib/bson/time_with_zone.rb
CHANGED
data/lib/bson/timestamp.rb
CHANGED
data/lib/bson/true_class.rb
CHANGED
data/lib/bson/undefined.rb
CHANGED
data/lib/bson/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -13,5 +13,5 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
module BSON
|
16
|
-
VERSION = "4.
|
16
|
+
VERSION = "4.9.3".freeze
|
17
17
|
end
|
data/spec/bson/array_spec.rb
CHANGED