bson 2.3.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bson might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4fd6495323d94fea442f4e61c9338529f5164418
4
- data.tar.gz: ab4f5d9674132ecced648aa3e4470660ecd2f900
3
+ metadata.gz: 5e51b7ae94371082cd621f26b85adbe629665bd0
4
+ data.tar.gz: 4073b003473247e42ebaeb1036d478a4390688f5
5
5
  SHA512:
6
- metadata.gz: 0738c3815003a964d0e5e8ce8bb1837dc64d73393dffc9478a3cb9cfe03e22aac8b77431ba7da361281ac747ef0bd1bd832b6f322d21a219c5e83622aaee956b
7
- data.tar.gz: 975f07b5635d3dd4899c020e4fcb0e3bfc5a51fd56ce042af0af1e50f7cb55be2ab46d89ad8fc7d42f51c4a50aa9925ebb73952135329eaaf77bf3a0aba13691
6
+ metadata.gz: 8fdcaa1935708f0444225be5c8d27e74d5b2e8ef7e42a87ef0c9a228ffe6422e83dbb9ed2857208304772168d09b4b8f4c7a6f4e34b788cbd88b3bda685db9ef
7
+ data.tar.gz: 70d353c0099e3a1df936f08bc2cbe5439661f64e441422db79d04c2664e33fe66d30bef0e992481c49097eb1bca5f30f292d5e69691dba3f6e09f3955f59a955
@@ -1,6 +1,28 @@
1
1
  BSON Changelog
2
2
  ==============
3
3
 
4
+ ## 3.0.0
5
+
6
+ ### Backwards Incompatible Changes
7
+
8
+ * [RUBY-852](https://jira.mongodb.org/browse/RUBY-852) Regular expressions that
9
+ are deserialized now return a `BSON::Regexp::Raw` instead of a `Regexp` object.
10
+ In order to get the regular expression compiled, call `#compile` on the returned object.
11
+
12
+ raw.compile
13
+
14
+ ### New Features
15
+
16
+ * `BSON::Binary` now implements `#inspect` with a truncated view of the data for
17
+ better readability.
18
+
19
+ ### Bug Fixes
20
+
21
+ * The native object id generation was fixed to match the raw Ruby. (Conrad Irwin)
22
+
23
+ * [#23](http://github.com/mongodb/bson-ruby/pull/23):
24
+ `BSON::Binary` types can be now used as hash keys. (Adam Wróbel)
25
+
4
26
  ## 2.2.3
5
27
 
6
28
  ### Bug Fixes
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- BSON [![Build Status](https://secure.travis-ci.org/mongodb/bson-ruby.png?branch=master&.png)](http://travis-ci.org/mongodb/bson-ruby) [![Code Climate](https://codeclimate.com/github/mongodb/bson-ruby.png)](https://codeclimate.com/github/mongodb/bson-ruby) [![Coverage Status](https://coveralls.io/repos/mongodb/bson-ruby/badge.png?branch=master)](https://coveralls.io/r/mongodb/bson-ruby?branch=master)
1
+ BSON [![Build Status](https://secure.travis-ci.org/mongodb/bson-ruby.png?branch=master&.png)](http://travis-ci.org/mongodb/bson-ruby) [![Code Climate](https://codeclimate.com/github/mongodb/bson-ruby.png)](https://codeclimate.com/github/mongodb/bson-ruby) [![Coverage Status](https://coveralls.io/repos/mongodb/bson-ruby/badge.png?branch=master)](https://coveralls.io/r/mongodb/bson-ruby?branch=master) [![Inline docs](http://inch-ci.org/github/mongodb/bson-ruby.svg?branch=master)](http://inch-ci.org/github/mongodb/bson-ruby)
2
2
  ====
3
3
 
4
4
  An implementation of the BSON specification in Ruby.
@@ -242,10 +242,13 @@ static VALUE rb_object_id_generator_next(int argc, VALUE* args, VALUE self)
242
242
  t = htonl(NUM2UINT(rb_funcall(*args, rb_intern("to_i"), 0)));
243
243
  }
244
244
 
245
+ unsigned long c;
246
+ c = htonl(rb_bson_object_id_counter << 8);
247
+
245
248
  memcpy(&bytes, &t, 4);
246
249
  memcpy(&bytes[4], rb_bson_machine_id, 3);
247
250
  memcpy(&bytes[7], &pid, 2);
248
- memcpy(&bytes[9], (unsigned char*) &rb_bson_object_id_counter, 3);
251
+ memcpy(&bytes[9], (unsigned char*) &c, 3);
249
252
  rb_bson_object_id_counter++;
250
253
  return rb_str_new(bytes, 12);
251
254
  }
@@ -356,7 +359,7 @@ static VALUE rb_integer_to_bson_key(int argc, VALUE *argv, VALUE self)
356
359
  static VALUE rb_integer_from_bson_int32(VALUE self, VALUE bson)
357
360
  {
358
361
  const uint8_t *v = (const uint8_t*) RSTRING_PTR(bson);
359
- const uint32_t integer = v[0] + (v[1] << 8) + (v[2] << 16) + (v[3] << 24);
362
+ const int32_t integer = v[0] + (v[1] << 8) + (v[2] << 16) + (v[3] << 24);
360
363
  return INT2NUM(integer);
361
364
  }
362
365
 
@@ -68,6 +68,18 @@ module BSON
68
68
  return false unless other.is_a?(Binary)
69
69
  type == other.type && data == other.data
70
70
  end
71
+ alias eql? ==
72
+
73
+ # Generates a Fixnum hash value for this object.
74
+ #
75
+ # Allows using Binary as hash keys.
76
+ #
77
+ # @return [ Fixnum ]
78
+ #
79
+ # @since 2.3.1
80
+ def hash
81
+ data.hash + type.hash
82
+ end
71
83
 
72
84
  # Get the binary as JSON hash data.
73
85
  #
@@ -96,6 +108,18 @@ module BSON
96
108
  @type = type
97
109
  end
98
110
 
111
+ # Get a nice string for use with object inspection.
112
+ #
113
+ # @example Inspect the binary.
114
+ # object_id.inspect
115
+ #
116
+ # @return [ String ] The binary in form BSON::Binary:object_id
117
+ #
118
+ # @since 2.3.0
119
+ def inspect
120
+ "<BSON::Binary:0x#{object_id} type=#{type} data=#{data[0, 8]}...>"
121
+ end
122
+
99
123
  # Encode the binary type
100
124
  #
101
125
  # @example Encode the binary.
@@ -14,7 +14,7 @@
14
14
 
15
15
  module BSON
16
16
 
17
- # Represents a $maxKey type, which compares less than any other value in the
17
+ # Represents a boolean type, which compares less than any other value in the
18
18
  # specification.
19
19
  #
20
20
  # @see http://bsonspec.org/#/specification
@@ -118,13 +118,13 @@ module BSON
118
118
  # Get a nice string for use with object inspection.
119
119
  #
120
120
  # @example Inspect the object id.
121
- # obhect_id.inspect
121
+ # object_id.inspect
122
122
  #
123
123
  # @return [ String ] The object id in form BSON::ObjectId('id')
124
124
  #
125
125
  # @since 2.0.0
126
126
  def inspect
127
- "BSON::ObjectId('#{to_s}')"
127
+ "<BSON::ObjectId:0x#{object_id} data=#{to_s}>"
128
128
  end
129
129
 
130
130
  # Dump the raw bson when calling Marshal.dump.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2015 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.
@@ -82,7 +82,48 @@ module BSON
82
82
  (options & ::Regexp::MULTILINE != 0) ? "ms" : NO_VALUE
83
83
  end
84
84
 
85
+ # Represents the raw values for the regular expression.
86
+ #
87
+ # @see https://jira.mongodb.org/browse/RUBY-698
88
+ #
89
+ # @since 3.0.0
90
+ class Raw
91
+
92
+ # @return [ String ] pattern The regex pattern.
93
+ attr_reader :pattern
94
+
95
+ # @return [ Integer ] options The options.
96
+ attr_reader :options
97
+
98
+ # Compile the Regular expression into the native type.
99
+ #
100
+ # @example Compile the regular expression.
101
+ # raw.compile
102
+ #
103
+ # @return [ ::Regexp ] The compiled regular expression.
104
+ #
105
+ # @since 3.0.0
106
+ def compile
107
+ @compiled ||= ::Regexp.new(pattern, options)
108
+ end
109
+
110
+ # Initialize the new raw regular expression.
111
+ #
112
+ # @example Initialize the raw regexp.
113
+ # Raw.new(pattern, options)
114
+ #
115
+ # @param [ String ] pattern The regular expression pattern.
116
+ # @param [ Integer ] options The options.
117
+ #
118
+ # @since 3.0.0
119
+ def initialize(pattern, options)
120
+ @pattern = pattern
121
+ @options = options
122
+ end
123
+ end
124
+
85
125
  module ClassMethods
126
+
86
127
  # Deserialize the regular expression from BSON.
87
128
  #
88
129
  # @param [ BSON ] bson The bson representing a regular expression.
@@ -105,8 +146,7 @@ module BSON
105
146
  options |= ::Regexp::EXTENDED
106
147
  end
107
148
  end
108
-
109
- new(pattern, options)
149
+ Raw.new(pattern, options)
110
150
  end
111
151
  end
112
152
 
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2015 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 = "2.3.0"
16
+ VERSION = "3.0.0"
17
17
  end
@@ -15,6 +15,44 @@
15
15
  require "spec_helper"
16
16
 
17
17
  describe BSON::Binary do
18
+ let(:testing1) { described_class.new("testing") }
19
+ let(:testing2) { described_class.new("testing") }
20
+ let(:not_testing) { described_class.new("not testing") }
21
+
22
+ describe "#eql?" do
23
+ context "for two equal objects" do
24
+ it "returns true" do
25
+ expect(testing1).to eql(testing2)
26
+ end
27
+ end
28
+
29
+ context "for two different objects" do
30
+ it "returns false" do
31
+ expect(testing1).not_to eql(not_testing)
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "#hash" do
37
+ context "for two equal objects" do
38
+ it "is the same" do
39
+ expect(testing1.hash).to eq(testing2.hash)
40
+ end
41
+ end
42
+
43
+ context "for two different objects" do
44
+ it "is different" do
45
+ expect(testing1.hash).not_to eq(not_testing.hash)
46
+ end
47
+ end
48
+ end
49
+
50
+ let(:hash) do { testing1 => "my value" } end
51
+
52
+ it "can be used as Hash key" do
53
+ expect(hash[testing2]).to eq("my value")
54
+ expect(hash[not_testing]).to be_nil
55
+ end
18
56
 
19
57
  describe "#as_json" do
20
58
 
@@ -46,6 +84,17 @@ describe BSON::Binary do
46
84
  end
47
85
  end
48
86
 
87
+ describe '#inspect' do
88
+
89
+ let(:object) do
90
+ described_class.new('testing123', :user)
91
+ end
92
+
93
+ it 'returns the truncated data and type' do
94
+ expect(object.inspect).to eq("<BSON::Binary:0x#{object.object_id} type=user data=testing1...>")
95
+ end
96
+ end
97
+
49
98
  describe "#to_bson/#from_bson" do
50
99
 
51
100
  let(:type) { 5.chr }
@@ -723,7 +723,13 @@ describe BSON::Document do
723
723
  described_class["type", /^gültig/]
724
724
  end
725
725
 
726
- it_behaves_like "a document able to handle utf-8"
726
+ let(:deserialized) do
727
+ described_class.from_bson(StringIO.new(document.to_bson))
728
+ end
729
+
730
+ it "serializes and deserializes properly" do
731
+ expect(deserialized['type'].compile).to eq(/^gültig/)
732
+ end
727
733
  end
728
734
 
729
735
  context "when the symbols are utf-8" do
@@ -25,4 +25,18 @@ describe BSON::Int32 do
25
25
  it_behaves_like "a bson element"
26
26
  it_behaves_like "a deserializable bson element"
27
27
  end
28
+
29
+ describe "when the integer is negative" do
30
+ let(:decoded) { -1 }
31
+ let(:encoded) {StringIO.new([ -1 ].pack(BSON::Int32::PACK))}
32
+ let(:decoded_2) { -50 }
33
+ let(:encoded_2) {StringIO.new([ -50 ].pack(BSON::Int32::PACK))}
34
+ it "decodes a -1 correctly" do
35
+ expect(BSON::Int32.from_bson(encoded)).to eq(decoded)
36
+ end
37
+ it "decodes a -50 correctly" do
38
+ expect(BSON::Int32.from_bson(encoded_2)).to eq(decoded_2)
39
+ end
40
+ end
41
+
28
42
  end
@@ -390,7 +390,7 @@ describe BSON::ObjectId do
390
390
  end
391
391
 
392
392
  it "returns the inspection with the object id to_s" do
393
- expect(object_id.inspect).to eq("BSON::ObjectId('#{object_id.to_s}')")
393
+ expect(object_id.inspect).to eq("<BSON::ObjectId:0x#{object_id.object_id} data=#{object_id.to_s}>")
394
394
  end
395
395
  end
396
396
 
@@ -36,6 +36,14 @@ describe Regexp do
36
36
  let(:type) { 11.chr }
37
37
  let(:obj) { /test/ }
38
38
 
39
+ let(:io) do
40
+ StringIO.new(bson)
41
+ end
42
+
43
+ let(:result) do
44
+ described_class.from_bson(io).compile
45
+ end
46
+
39
47
  it_behaves_like "a bson element"
40
48
 
41
49
  context "when the regexp has no options" do
@@ -44,7 +52,10 @@ describe Regexp do
44
52
  let(:bson) { "#{obj.source}#{BSON::NULL_BYTE}#{BSON::NULL_BYTE}" }
45
53
 
46
54
  it_behaves_like "a serializable bson element"
47
- it_behaves_like "a deserializable bson element"
55
+
56
+ it "deserializes from bson" do
57
+ expect(result).to eq(obj)
58
+ end
48
59
  end
49
60
 
50
61
  context "when the regexp has options" do
@@ -55,7 +66,10 @@ describe Regexp do
55
66
  let(:bson) { "#{obj.source}#{BSON::NULL_BYTE}i#{BSON::NULL_BYTE}" }
56
67
 
57
68
  it_behaves_like "a serializable bson element"
58
- it_behaves_like "a deserializable bson element"
69
+
70
+ it "deserializes from bson" do
71
+ expect(result).to eq(obj)
72
+ end
59
73
  end
60
74
 
61
75
  context "when matching multiline" do
@@ -64,7 +78,10 @@ describe Regexp do
64
78
  let(:bson) { "#{obj.source}#{BSON::NULL_BYTE}ms#{BSON::NULL_BYTE}" }
65
79
 
66
80
  it_behaves_like "a serializable bson element"
67
- it_behaves_like "a deserializable bson element"
81
+
82
+ it "deserializes from bson" do
83
+ expect(result).to eq(obj)
84
+ end
68
85
  end
69
86
 
70
87
  context "when matching extended" do
@@ -73,7 +90,10 @@ describe Regexp do
73
90
  let(:bson) { "#{obj.source}#{BSON::NULL_BYTE}x#{BSON::NULL_BYTE}" }
74
91
 
75
92
  it_behaves_like "a serializable bson element"
76
- it_behaves_like "a deserializable bson element"
93
+
94
+ it "deserializes from bson" do
95
+ expect(result).to eq(obj)
96
+ end
77
97
  end
78
98
 
79
99
  context "when all options are present" do
@@ -82,7 +102,10 @@ describe Regexp do
82
102
  let(:bson) { "#{obj.source}#{BSON::NULL_BYTE}imsx#{BSON::NULL_BYTE}" }
83
103
 
84
104
  it_behaves_like "a serializable bson element"
85
- it_behaves_like "a deserializable bson element"
105
+
106
+ it "deserializes from bson" do
107
+ expect(result).to eq(obj)
108
+ end
86
109
  end
87
110
  end
88
111
  end
@@ -57,8 +57,12 @@ shared_examples_for "a deserializable bson element" do
57
57
  StringIO.new(bson)
58
58
  end
59
59
 
60
+ let(:result) do
61
+ described_class.from_bson(io)
62
+ end
63
+
60
64
  it "deserializes from bson" do
61
- expect(described_class.from_bson(io)).to eq(obj)
65
+ expect(result).to eq(obj)
62
66
  end
63
67
  end
64
68
 
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: 2.3.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Brock
@@ -11,30 +11,8 @@ authors:
11
11
  - Gary Murakami
12
12
  autorequire:
13
13
  bindir: bin
14
- cert_chain:
15
- - |
16
- -----BEGIN CERTIFICATE-----
17
- MIIDfDCCAmSgAwIBAgIBATANBgkqhkiG9w0BAQUFADBCMRQwEgYDVQQDDAtkcml2
18
- ZXItcnVieTEVMBMGCgmSJomT8ixkARkWBTEwZ2VuMRMwEQYKCZImiZPyLGQBGRYD
19
- Y29tMB4XDTE0MDIxOTE1MTEyNloXDTE1MDIxOTE1MTEyNlowQjEUMBIGA1UEAwwL
20
- ZHJpdmVyLXJ1YnkxFTATBgoJkiaJk/IsZAEZFgUxMGdlbjETMBEGCgmSJomT8ixk
21
- ARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANFdSAa8fRm1
22
- bAM9za6Z0fAH4g02bqM1NGnw8zJQrE/PFrFfY6IFCT2AsLfOwr1maVm7iU1+kdVI
23
- IQ+iI/9+E+ArJ+rbGV3dDPQ+SLl3mLT+vXjfjcxMqI2IW6UuVtt2U3Rxd4QU0kdT
24
- JxmcPYs5fDN6BgYc6XXgUjy3m+Kwha2pGctdciUOwEfOZ4RmNRlEZKCMLRHdFP8j
25
- 4WTnJSGfXDiuoXICJb5yOPOZPuaapPSNXp93QkUdsqdKC32I+KMpKKYGBQ6yisfA
26
- 5MyVPPCzLR1lP5qXVGJPnOqUAkvEUfCahg7EP9tI20qxiXrR6TSEraYhIFXL0EGY
27
- u8KAcPHm5KkCAwEAAaN9MHswCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
28
- BBYEFFt3WbF+9JpUjAoj62cQBgNb8HzXMCAGA1UdEQQZMBeBFWRyaXZlci1ydWJ5
29
- QDEwZ2VuLmNvbTAgBgNVHRIEGTAXgRVkcml2ZXItcnVieUAxMGdlbi5jb20wDQYJ
30
- KoZIhvcNAQEFBQADggEBALGvdxHF+CnH6QO4PeIce3S8EHuHsYiGLk4sWgNGZkjD
31
- V3C4XjlI8rQZxalwQwcauacOGj9x94flWUXruEF7+rjUtig7OIrQK2+uVg86vl8r
32
- xy1n2s1d31KsuazEVExe5o19tnVbI9+30P9qPkS+NgaellXpj5c5qnJUGn5BJtzo
33
- 3D001zXpVnuZvCcE/A4fQ+BEM0zm0oOmA/gWIAFrufOL9oYg1881dRZ+kQytF/9c
34
- JrZM8w8wGbIOeLtoQqa7HB/jOYbTahH7KMNh2LHAbOR93hNIJxVRa4iwxiMQ75tN
35
- 9WUIAJ4AEtjwRg1Bz0OwDo3aucPCBpx77+/FWhv7JYY=
36
- -----END CERTIFICATE-----
37
- date: 2014-06-02 00:00:00.000000000 Z
14
+ cert_chain: []
15
+ date: 2015-02-18 00:00:00.000000000 Z
38
16
  dependencies: []
39
17
  description: A full featured BSON specification implementation, in Ruby
40
18
  email:
Binary file
data.tar.gz.sig DELETED
@@ -1 +0,0 @@
1
- �0NU�י[���4�?�2���2<���BL����R����a��/�H�3-����Y��-i��e�z��<�SM���r���k�����*P��&� '����*���}����/e^bIY�Ϟ$����
metadata.gz.sig DELETED
Binary file