bson 4.11.0 → 4.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +4 -7
- data/ext/bson/bson-native.h +2 -0
- data/ext/bson/init.c +24 -1
- data/ext/bson/read.c +29 -0
- data/lib/bson/active_support.rb +1 -0
- data/lib/bson/array.rb +2 -1
- data/lib/bson/binary.rb +8 -5
- data/lib/bson/boolean.rb +2 -1
- data/lib/bson/code.rb +2 -1
- data/lib/bson/code_with_scope.rb +2 -1
- data/lib/bson/config.rb +1 -0
- data/lib/bson/date.rb +1 -0
- data/lib/bson/date_time.rb +1 -0
- data/lib/bson/db_pointer.rb +2 -1
- data/lib/bson/dbref.rb +125 -0
- data/lib/bson/decimal128/builder.rb +18 -15
- data/lib/bson/decimal128.rb +10 -9
- data/lib/bson/document.rb +61 -18
- data/lib/bson/environment.rb +1 -0
- data/lib/bson/error.rb +7 -0
- data/lib/bson/ext_json.rb +24 -11
- data/lib/bson/false_class.rb +2 -1
- data/lib/bson/float.rb +20 -31
- data/lib/bson/hash.rb +15 -6
- data/lib/bson/int32.rb +3 -2
- data/lib/bson/int64.rb +3 -2
- data/lib/bson/integer.rb +3 -2
- data/lib/bson/json.rb +1 -0
- data/lib/bson/max_key.rb +3 -2
- data/lib/bson/min_key.rb +3 -2
- data/lib/bson/nil_class.rb +2 -1
- data/lib/bson/object.rb +1 -0
- data/lib/bson/object_id.rb +4 -3
- data/lib/bson/open_struct.rb +1 -0
- data/lib/bson/regexp.rb +17 -6
- data/lib/bson/registry.rb +1 -0
- data/lib/bson/specialized.rb +1 -0
- data/lib/bson/string.rb +3 -2
- data/lib/bson/symbol.rb +2 -1
- data/lib/bson/time.rb +4 -3
- data/lib/bson/time_with_zone.rb +1 -0
- data/lib/bson/timestamp.rb +3 -2
- data/lib/bson/true_class.rb +2 -1
- data/lib/bson/undefined.rb +2 -1
- data/lib/bson/version.rb +2 -1
- data/lib/bson.rb +6 -4
- data/spec/README.md +14 -0
- data/spec/bson/binary_spec.rb +1 -1
- data/spec/bson/binary_uuid_spec.rb +12 -0
- data/spec/bson/byte_buffer_spec.rb +80 -1
- data/spec/bson/dbref_spec.rb +461 -0
- data/spec/bson/document_as_spec.rb +46 -0
- data/spec/bson/document_spec.rb +43 -1
- data/spec/bson/ext_json_parse_spec.rb +37 -0
- data/spec/bson/hash_as_spec.rb +57 -0
- data/spec/bson/int64_spec.rb +4 -24
- data/spec/bson/raw_spec.rb +7 -1
- data/spec/bson/regexp_spec.rb +52 -0
- data/spec/runners/common_driver.rb +1 -1
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/cluster_config.rb +221 -0
- data/spec/shared/lib/mrss/constraints.rb +346 -0
- data/spec/shared/lib/mrss/docker_runner.rb +265 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +191 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +115 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +152 -0
- data/spec/shared/lib/mrss/utils.rb +15 -0
- data/spec/shared/share/Dockerfile.erb +231 -0
- data/spec/shared/shlib/distro.sh +73 -0
- data/spec/shared/shlib/server.sh +290 -0
- data/spec/shared/shlib/set_env.sh +128 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/spec_tests/data/corpus/binary.json +33 -0
- data/spec/spec_tests/data/corpus/dbref.json +21 -1
- data/spec/spec_tests/data/corpus/document.json +4 -0
- data/spec/spec_tests/data/corpus/regex.json +2 -2
- data/spec/spec_tests/data/corpus/top.json +20 -9
- data/spec/support/spec_config.rb +2 -1
- data.tar.gz.sig +0 -0
- metadata +137 -101
- metadata.gz.sig +0 -0
- data/lib/bson_native.bundle +0 -0
data/lib/bson/timestamp.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
3
|
#
|
3
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -26,12 +27,12 @@ module BSON
|
|
26
27
|
# A timestamp is type 0x11 in the BSON spec.
|
27
28
|
#
|
28
29
|
# @since 2.0.0
|
29
|
-
BSON_TYPE = 17.chr
|
30
|
+
BSON_TYPE = ::String.new(17.chr, encoding: BINARY).freeze
|
30
31
|
|
31
32
|
# Error message if an object other than a Timestamp is compared with this object.
|
32
33
|
#
|
33
34
|
# @since 4.3.0
|
34
|
-
COMPARISON_ERROR_MESSAGE = 'comparison of %s with Timestamp failed'
|
35
|
+
COMPARISON_ERROR_MESSAGE = 'comparison of %s with Timestamp failed'
|
35
36
|
|
36
37
|
# @!attribute seconds
|
37
38
|
# @return [ Integer ] The number of seconds.
|
data/lib/bson/true_class.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
3
|
#
|
3
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -25,7 +26,7 @@ module BSON
|
|
25
26
|
# A true value in the BSON spec is 0x01.
|
26
27
|
#
|
27
28
|
# @since 2.0.0
|
28
|
-
TRUE_BYTE = 1.chr
|
29
|
+
TRUE_BYTE = ::String.new(1.chr, encoding: BINARY).freeze
|
29
30
|
|
30
31
|
# The BSON type for true values is the general boolean type of 0x08.
|
31
32
|
#
|
data/lib/bson/undefined.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
3
|
#
|
3
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -25,7 +26,7 @@ module BSON
|
|
25
26
|
# Undefined is type 0x06 in the BSON spec.
|
26
27
|
#
|
27
28
|
# @since 2.0.0
|
28
|
-
BSON_TYPE = 6.chr
|
29
|
+
BSON_TYPE = ::String.new(6.chr, encoding: BINARY).freeze
|
29
30
|
|
30
31
|
# Determine if undefined is equal to another object.
|
31
32
|
#
|
data/lib/bson/version.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
3
|
#
|
3
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -13,5 +14,5 @@
|
|
13
14
|
# limitations under the License.
|
14
15
|
|
15
16
|
module BSON
|
16
|
-
VERSION = "4.
|
17
|
+
VERSION = "4.13.0"
|
17
18
|
end
|
data/lib/bson.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
3
|
#
|
3
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -38,22 +39,22 @@ module BSON
|
|
38
39
|
# Constant for binary string encoding.
|
39
40
|
#
|
40
41
|
# @since 2.0.0
|
41
|
-
BINARY = "BINARY"
|
42
|
+
BINARY = "BINARY"
|
42
43
|
|
43
44
|
# Constant for bson types that don't actually serialize a value.
|
44
45
|
#
|
45
46
|
# @since 2.0.0
|
46
|
-
NO_VALUE =
|
47
|
+
NO_VALUE = ::String.new(encoding: BINARY).freeze
|
47
48
|
|
48
49
|
# Constant for a null byte (0x00).
|
49
50
|
#
|
50
51
|
# @since 2.0.0
|
51
|
-
NULL_BYTE = 0.chr
|
52
|
+
NULL_BYTE = ::String.new(0.chr, encoding: BINARY).freeze
|
52
53
|
|
53
54
|
# Constant for UTF-8 string encoding.
|
54
55
|
#
|
55
56
|
# @since 2.0.0
|
56
|
-
UTF8 = "UTF-8"
|
57
|
+
UTF8 = "UTF-8"
|
57
58
|
end
|
58
59
|
|
59
60
|
require "bson/config"
|
@@ -78,6 +79,7 @@ require "bson/ext_json"
|
|
78
79
|
require "bson/false_class"
|
79
80
|
require "bson/float"
|
80
81
|
require "bson/hash"
|
82
|
+
require "bson/dbref"
|
81
83
|
require "bson/open_struct"
|
82
84
|
require "bson/max_key"
|
83
85
|
require "bson/min_key"
|
data/spec/README.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Running BSON Ruby Tests
|
2
|
+
|
3
|
+
## Quick Start
|
4
|
+
|
5
|
+
The test suite requires shared tooling that is stored in a separate repository
|
6
|
+
and is referenced as a submodule. After checking out the desired bson-ruby
|
7
|
+
branch, check out the matching submodules:
|
8
|
+
|
9
|
+
git submodule init
|
10
|
+
git submodule update
|
11
|
+
|
12
|
+
Then, to run the test suite:
|
13
|
+
|
14
|
+
rake
|
data/spec/bson/binary_spec.rb
CHANGED
@@ -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-
|
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
|
@@ -42,7 +42,6 @@ describe BSON::ByteBuffer do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
45
|
context 'when the byte buffer is initialized with some bytes' do
|
47
46
|
|
48
47
|
let(:buffer) do
|
@@ -53,6 +52,50 @@ describe BSON::ByteBuffer do
|
|
53
52
|
expect(buffer.length).to eq(2)
|
54
53
|
end
|
55
54
|
end
|
55
|
+
|
56
|
+
context 'after the byte buffer was read from' do
|
57
|
+
|
58
|
+
let(:buffer) do
|
59
|
+
described_class.new({}.to_bson.to_s)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'returns the number of bytes remaining in the buffer' do
|
63
|
+
expect(buffer.length).to eq(5)
|
64
|
+
buffer.get_int32
|
65
|
+
expect(buffer.length).to eq(1)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'after the byte buffer was converted to string' do
|
70
|
+
|
71
|
+
shared_examples 'returns the total buffer length' do
|
72
|
+
it 'returns the total buffer length' do
|
73
|
+
expect(buffer.length).to eq(5)
|
74
|
+
buffer.to_s.length.should == 5
|
75
|
+
expect(buffer.length).to eq(5)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'read buffer' do
|
80
|
+
|
81
|
+
let(:buffer) do
|
82
|
+
described_class.new({}.to_bson.to_s)
|
83
|
+
end
|
84
|
+
|
85
|
+
include_examples 'returns the total buffer length'
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'write buffer' do
|
89
|
+
|
90
|
+
let(:buffer) do
|
91
|
+
described_class.new.tap do |buffer|
|
92
|
+
buffer.put_bytes('hello')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
include_examples 'returns the total buffer length'
|
97
|
+
end
|
98
|
+
end
|
56
99
|
end
|
57
100
|
|
58
101
|
describe '#rewind!' do
|
@@ -148,4 +191,40 @@ describe BSON::ByteBuffer do
|
|
148
191
|
end
|
149
192
|
end
|
150
193
|
end
|
194
|
+
|
195
|
+
describe '#to_s' do
|
196
|
+
context 'read buffer' do
|
197
|
+
let(:buffer) do
|
198
|
+
described_class.new("\x18\x00\x00\x00*\x00\x00\x00")
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'returns the data' do
|
202
|
+
buffer.to_s.should == "\x18\x00\x00\x00*\x00\x00\x00"
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'returns the remaining buffer contents after a read' do
|
206
|
+
buffer.to_s.should == "\x18\x00\x00\x00*\x00\x00\x00"
|
207
|
+
buffer.get_int32.should == 24
|
208
|
+
buffer.to_s.should == "*\x00\x00\x00"
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context 'write buffer' do
|
213
|
+
let(:buffer) do
|
214
|
+
described_class.new.tap do |buffer|
|
215
|
+
buffer.put_int32(24)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'returns the data' do
|
220
|
+
buffer.to_s.should == "\x18\x00\x00\x00".force_encoding('binary')
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'returns the complete buffer contents after a write' do
|
224
|
+
buffer.to_s.should == "\x18\x00\x00\x00".force_encoding('binary')
|
225
|
+
buffer.put_int32(42)
|
226
|
+
buffer.to_s.should == "\x18\x00\x00\x00*\x00\x00\x00".force_encoding('binary')
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
151
230
|
end
|