bson 4.1.0-java → 4.1.1-java

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
  SHA1:
3
- metadata.gz: 5cbded2c27d698be26bb72f36921c70e1e8193d2
4
- data.tar.gz: 4173ded97b83024341bf8f8922acd60d70d12b6b
3
+ metadata.gz: 937c39adeba926daec9cda4e1a3f33ed95d409df
4
+ data.tar.gz: 16b8d33f71e2a25762fb10489115dad09ac16b02
5
5
  SHA512:
6
- metadata.gz: 054ee98826bd504e44d6c1871e77deb4355f2eabf1907bc23762b95d50445bb64b72c943fa91dcf00e5e15652fdd36860569812f6e3d6446de52eb766bab6211
7
- data.tar.gz: 6b4c01788ca478e953d2d127779f010a3d3cfc6ccb13803165d9525e83067f1102d90a69a4d39719d5fa8d016da7ae8c046bb9256753c6b9b3fb9b6aa0a92e80
6
+ metadata.gz: 6b4734870f5a0111a4129295f8e851cd65578d0b2b54aae09e15965a8b0408ec6e61f583c7b47798b10c2f3997c11b8db48fa8861a53f4db8499cbb121d047f2
7
+ data.tar.gz: 9f6f660b38963ce96184acaa73f6ac4906fb8b9df2318aa093004e56ed48132801c8c650996c232299ae16e78442a8a4ea6c890170bf429f317eb977e4eb6027
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/bson-ruby.jar CHANGED
Binary file
data/lib/bson/array.rb CHANGED
@@ -40,13 +40,13 @@ module BSON
40
40
  # @see http://bsonspec.org/#/specification
41
41
  #
42
42
  # @since 2.0.0
43
- def to_bson(buffer = ByteBuffer.new)
43
+ def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
44
44
  position = buffer.length
45
45
  buffer.put_int32(0)
46
46
  each_with_index do |value, index|
47
47
  buffer.put_byte(value.bson_type)
48
48
  buffer.put_cstring(index.to_s)
49
- value.to_bson(buffer)
49
+ value.to_bson(buffer, validating_keys)
50
50
  end
51
51
  buffer.put_byte(NULL_BYTE)
52
52
  buffer.replace_int32(position, buffer.length - position)
data/lib/bson/binary.rb CHANGED
@@ -129,7 +129,7 @@ module BSON
129
129
  # @see http://bsonspec.org/#/specification
130
130
  #
131
131
  # @since 2.0.0
132
- def to_bson(buffer = ByteBuffer.new)
132
+ def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
133
133
  position = buffer.length
134
134
  buffer.put_int32(0)
135
135
  buffer.put_byte(SUBTYPES[type])
data/lib/bson/code.rb CHANGED
@@ -81,7 +81,7 @@ module BSON
81
81
  # @see http://bsonspec.org/#/specification
82
82
  #
83
83
  # @since 2.0.0
84
- def to_bson(buffer = ByteBuffer.new)
84
+ def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
85
85
  buffer.put_string(javascript) # @todo: was formerly to_bson_string
86
86
  end
87
87
 
@@ -87,7 +87,7 @@ module BSON
87
87
  # @see http://bsonspec.org/#/specification
88
88
  #
89
89
  # @since 2.0.0
90
- def to_bson(buffer = ByteBuffer.new)
90
+ def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
91
91
  position = buffer.length
92
92
  buffer.put_int32(0)
93
93
  buffer.put_string(javascript)
data/lib/bson/date.rb CHANGED
@@ -34,7 +34,7 @@ module BSON
34
34
  # @see http://bsonspec.org/#/specification
35
35
  #
36
36
  # @since 2.1.0
37
- def to_bson(buffer = ByteBuffer.new)
37
+ def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
38
38
  ::Time.utc(year, month, day).to_bson(buffer)
39
39
  end
40
40
 
@@ -34,7 +34,7 @@ module BSON
34
34
  # @see http://bsonspec.org/#/specification
35
35
  #
36
36
  # @since 2.1.0
37
- def to_bson(buffer = ByteBuffer.new)
37
+ def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
38
38
  to_time.to_bson(buffer)
39
39
  end
40
40
  end
@@ -49,7 +49,7 @@ module BSON
49
49
  # @see http://bsonspec.org/#/specification
50
50
  #
51
51
  # @since 2.0.0
52
- def to_bson(buffer = ByteBuffer.new)
52
+ def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
53
53
  buffer.put_byte(FALSE_BYTE)
54
54
  end
55
55
  end
data/lib/bson/float.rb CHANGED
@@ -42,7 +42,7 @@ module BSON
42
42
  # @see http://bsonspec.org/#/specification
43
43
  #
44
44
  # @since 2.0.0
45
- def to_bson(buffer = ByteBuffer.new)
45
+ def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
46
46
  buffer.put_double(self)
47
47
  end
48
48
 
data/lib/bson/hash.rb CHANGED
@@ -43,7 +43,7 @@ module BSON
43
43
  each do |field, value|
44
44
  buffer.put_byte(value.bson_type)
45
45
  buffer.put_cstring(field.to_bson_key(validating_keys))
46
- value.to_bson(buffer)
46
+ value.to_bson(buffer, validating_keys)
47
47
  end
48
48
  buffer.put_byte(NULL_BYTE)
49
49
  buffer.replace_int32(position, buffer.length - position)
data/lib/bson/integer.rb CHANGED
@@ -103,7 +103,7 @@ module BSON
103
103
  # @see http://bsonspec.org/#/specification
104
104
  #
105
105
  # @since 2.0.0
106
- def to_bson(buffer = ByteBuffer.new)
106
+ def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
107
107
  if bson_int32?
108
108
  buffer.put_int32(self)
109
109
  elsif bson_int64?
@@ -168,7 +168,7 @@ module BSON
168
168
  # @see http://bsonspec.org/#/specification
169
169
  #
170
170
  # @since 2.0.0
171
- def to_bson(buffer = ByteBuffer.new)
171
+ def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
172
172
  buffer.put_bytes(generate_data)
173
173
  end
174
174
 
data/lib/bson/regexp.rb CHANGED
@@ -84,7 +84,7 @@ module BSON
84
84
  # @see http://bsonspec.org/#/specification
85
85
  #
86
86
  # @since 2.0.0
87
- def to_bson(buffer = ByteBuffer.new)
87
+ def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
88
88
  buffer.put_cstring(source)
89
89
  buffer.put_cstring(bson_options)
90
90
  end
@@ -45,7 +45,7 @@ module BSON
45
45
  # @return [ String ] An empty string.
46
46
  #
47
47
  # @since 2.0.0
48
- def to_bson(buffer = ByteBuffer.new)
48
+ def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
49
49
  buffer
50
50
  end
51
51
 
data/lib/bson/string.rb CHANGED
@@ -45,7 +45,7 @@ module BSON
45
45
  # @see http://bsonspec.org/#/specification
46
46
  #
47
47
  # @since 2.0.0
48
- def to_bson(buffer = ByteBuffer.new)
48
+ def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
49
49
  buffer.put_string(self)
50
50
  end
51
51
 
data/lib/bson/symbol.rb CHANGED
@@ -56,7 +56,7 @@ module BSON
56
56
  # @see http://bsonspec.org/#/specification
57
57
  #
58
58
  # @since 2.0.0
59
- def to_bson(buffer = ByteBuffer.new)
59
+ def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
60
60
  to_s.to_bson(buffer)
61
61
  end
62
62
 
data/lib/bson/time.rb CHANGED
@@ -37,7 +37,7 @@ module BSON
37
37
  # @see http://bsonspec.org/#/specification
38
38
  #
39
39
  # @since 2.0.0
40
- def to_bson(buffer = ByteBuffer.new)
40
+ def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
41
41
  buffer.put_int64((to_i * 1000) + (usec / 1000))
42
42
  end
43
43
 
@@ -87,7 +87,7 @@ module BSON
87
87
  # @see http://bsonspec.org/#/specification
88
88
  #
89
89
  # @since 2.0.0
90
- def to_bson(buffer = ByteBuffer.new)
90
+ def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
91
91
  buffer.put_int32(increment)
92
92
  buffer.put_int32(seconds)
93
93
  end
@@ -49,7 +49,7 @@ module BSON
49
49
  # @see http://bsonspec.org/#/specification
50
50
  #
51
51
  # @since 2.0.0
52
- def to_bson(buffer = ByteBuffer.new)
52
+ def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
53
53
  buffer.put_byte(TRUE_BYTE)
54
54
  end
55
55
  end
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.1.0".freeze
16
+ VERSION = "4.1.1".freeze
17
17
  end
@@ -27,6 +27,111 @@ describe Array do
27
27
  it_behaves_like "a bson element"
28
28
  it_behaves_like "a serializable bson element"
29
29
  it_behaves_like "a deserializable bson element"
30
+
31
+ context "when the array has documents containing invalid keys" do
32
+
33
+ let(:obj) do
34
+ [ { "$testing" => "value" } ]
35
+ end
36
+
37
+ context "when validating keys" do
38
+
39
+ context "when validating globally" do
40
+
41
+ before do
42
+ BSON::Config.validating_keys = true
43
+ end
44
+
45
+ after do
46
+ BSON::Config.validating_keys = false
47
+ end
48
+
49
+ it "raises an error" do
50
+ expect {
51
+ obj.to_bson
52
+ }.to raise_error(BSON::String::IllegalKey)
53
+ end
54
+ end
55
+
56
+ context "when validating locally" do
57
+
58
+ it "raises an error" do
59
+ expect {
60
+ obj.to_bson(BSON::ByteBuffer.new, true)
61
+ }.to raise_error(BSON::String::IllegalKey)
62
+ end
63
+
64
+ context "when serializing different types" do
65
+
66
+ let(:obj) do
67
+ [ BSON::Binary.new("testing", :generic),
68
+ BSON::Code.new("this.value = 5"),
69
+ BSON::CodeWithScope.new("this.value = val", "test"),
70
+ Date.new(2012, 1, 1),
71
+ Time.utc(2012, 1, 1),
72
+ DateTime.new(2012, 1, 1, 0, 0, 0),
73
+ false,
74
+ 1.2332,
75
+ Integer::MAX_32BIT - 1,
76
+ BSON::ObjectId.new,
77
+ /\W+/i,
78
+ 'a string',
79
+ :a_symbol,
80
+ Time.utc(2012, 1, 1, 0, 0, 0),
81
+ BSON::Timestamp.new(1, 10),
82
+ true,
83
+ { "$testing" => "value" }
84
+ ]
85
+ end
86
+
87
+ it "raises an error" do
88
+ expect {
89
+ obj.to_bson(BSON::ByteBuffer.new, true)
90
+ }.to raise_error(BSON::String::IllegalKey)
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ context "when not validating keys" do
97
+
98
+ let(:bson) do
99
+ BSON::Document["0", { "$testing" => "value" }].to_bson.to_s
100
+ end
101
+
102
+ it "serializes the hash" do
103
+ expect(obj.to_bson.to_s).to eq(bson)
104
+ end
105
+
106
+ context "when serializing different types" do
107
+
108
+ let(:obj) do
109
+ [ BSON::Binary.new("testing", :generic),
110
+ BSON::Code.new("this.value = 5"),
111
+ BSON::CodeWithScope.new("this.value = val", "test"),
112
+ Date.new(2012, 1, 1),
113
+ Time.utc(2012, 1, 1),
114
+ DateTime.new(2012, 1, 1, 0, 0, 0),
115
+ false,
116
+ 1.2332,
117
+ Integer::MAX_32BIT - 1,
118
+ BSON::ObjectId.new,
119
+ /\W+/i,
120
+ 'a string',
121
+ :a_symbol,
122
+ Time.utc(2012, 1, 1, 0, 0, 0),
123
+ BSON::Timestamp.new(1, 10),
124
+ true,
125
+ { "$testing" => "value" }
126
+ ]
127
+ end
128
+
129
+ it "serializes the hash" do
130
+ expect(obj.to_bson.length).to eq(251)
131
+ end
132
+ end
133
+ end
134
+ end
30
135
  end
31
136
 
32
137
  describe "#to_bson_normalized_value" do
@@ -75,6 +75,19 @@ describe Hash do
75
75
  obj.to_bson
76
76
  }.to raise_error(BSON::String::IllegalKey)
77
77
  end
78
+
79
+ context "when the hash contains an array of documents containing invalid keys" do
80
+
81
+ let(:obj) do
82
+ { "array" => [{ "$testing" => "value" }] }
83
+ end
84
+
85
+ it "raises an error" do
86
+ expect {
87
+ obj.to_bson
88
+ }.to raise_error(BSON::String::IllegalKey)
89
+ end
90
+ end
78
91
  end
79
92
 
80
93
  context "when validating locally" do
@@ -84,6 +97,19 @@ describe Hash do
84
97
  obj.to_bson(BSON::ByteBuffer.new, true)
85
98
  }.to raise_error(BSON::String::IllegalKey)
86
99
  end
100
+
101
+ context "when the hash contains an array of documents containing invalid keys" do
102
+
103
+ let(:obj) do
104
+ { "array" => [{ "$testing" => "value" }] }
105
+ end
106
+
107
+ it "raises an error" do
108
+ expect {
109
+ obj.to_bson(BSON::ByteBuffer.new, true)
110
+ }.to raise_error(BSON::String::IllegalKey)
111
+ end
112
+ end
87
113
  end
88
114
  end
89
115
 
@@ -97,6 +123,22 @@ describe Hash do
97
123
  it "serializes the hash" do
98
124
  expect(obj.to_bson.to_s).to eq(bson)
99
125
  end
126
+
127
+ context "when the hash contains an array of documents containing invalid keys" do
128
+
129
+ let(:obj) do
130
+ { "array" => [{ "$testing" => "value" }] }
131
+ end
132
+
133
+ let(:bson) do
134
+ "#{45.to_bson.to_s}#{Array::BSON_TYPE}array#{BSON::NULL_BYTE}" +
135
+ "#{[{ "$testing" => "value" }].to_bson.to_s}#{BSON::NULL_BYTE}"
136
+ end
137
+
138
+ it "serializes the hash" do
139
+ expect(obj.to_bson.to_s).to eq(bson)
140
+ end
141
+ end
100
142
  end
101
143
  end
102
144
 
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.1.0
4
+ version: 4.1.1
5
5
  platform: java
6
6
  authors:
7
7
  - Tyler Brock
@@ -34,7 +34,7 @@ cert_chain:
34
34
  yVPbgNJA2D/PnLe8ZFMhgJf+VIA1V4oybP/o+9aqlghTtNfYHJpRCAluUiaywwXl
35
35
  KzD4mmIBpxtbWrWB3hx7tsVJmWx5zgO9aDAfvWnXfoo=
36
36
  -----END CERTIFICATE-----
37
- date: 2016-04-14 00:00:00.000000000 Z
37
+ date: 2016-04-27 00:00:00.000000000 Z
38
38
  dependencies: []
39
39
  description: A full featured BSON specification implementation, in Ruby
40
40
  email:
@@ -126,17 +126,17 @@ require_paths:
126
126
  - lib
127
127
  required_ruby_version: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: 1.9.3
132
132
  required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  requirements:
134
- - - '>='
134
+ - - ">="
135
135
  - !ruby/object:Gem::Version
136
136
  version: 1.3.6
137
137
  requirements: []
138
138
  rubyforge_project: bson
139
- rubygems_version: 2.4.5
139
+ rubygems_version: 2.4.8
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: Ruby Implementation of the BSON specification
metadata.gz.sig CHANGED
Binary file