bson 2.0.0.rc1 → 2.0.0.rc2

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: da650cd5a81e6fbf7d40be183308904d83359e54
4
- data.tar.gz: 1aa6c7977bbe2b62fb957d7f8435db70350407f6
3
+ metadata.gz: 26c195c903e73023d0f0ddbc6bd8b802965a2a32
4
+ data.tar.gz: 5a678021165a243c12330f9bc5fa8f192ea2beaa
5
5
  SHA512:
6
- metadata.gz: fd716b5ca171488c93c5d807d501684f31c23fd495466851fdead27a0a2b8c307856c8a014ad52923552792b3068bb65c5da08a2dbaa9089df1d95a7a3edba5d
7
- data.tar.gz: 2c6086856793c542f66d7394885a7620b434f334f995c644298aa367d4f9af5b5ff87f17cb7ee24494e52052afff0ea3ea3d51f780d44f75a21ebc4b3685df04
6
+ metadata.gz: ce3afab5e81c5c6179e715637693765e54fdb9d459b79684ec8210b862ec73b7940b10aa527bbf7bc9dfece19a69b01f4c86adccaadbf18f33ba5ec407cf9454
7
+ data.tar.gz: 55ebdf9995b846d805666bab644ca34df8b90d37ced302fe4eb2d921240d6a023290a84dd8ac651dac8cadcffea5a685ccb13858c90a59776d78b929c1f7b1bb
Binary file
data.tar.gz.sig CHANGED
@@ -1,3 +1 @@
1
- |���A��}�AE�aV��N ��|H��rSm�^�Zc*!#�~���4;Ct)��jJ�+���@�娵M-`�o#A#�@�L &ybwʦ�ߑsQ*���E��Bb��Ֆр��י�1��2��Hd]�OH���*d��Ʉ��&�
2
- 5�u�Xx���6�僑�J�19� G�7P�L�� �;S/�{�$'�Ν�IFK'H�Ӳw�}���=-c"E
3
- �O���Ih���*2�w� '�b�����ʄ?��n
1
+ ��wFh���&��w/�߾z�'-���z��ɸV��k��j�����RH�/���w�禞��md>�c��VU�3��TsGE"�*��'5������̯��G�< hs��%eA�*��������n��JQ�$��Q�`�����|�AU
@@ -70,13 +70,6 @@
70
70
  */
71
71
  static char rb_bson_array_indexes[BSON_INDEX_SIZE][BSON_INDEX_CHAR_SIZE];
72
72
 
73
- /**
74
- * BSON::BINARY
75
- *
76
- * @since 2.0.0
77
- */
78
- static VALUE rb_bson_binary;
79
-
80
73
  /**
81
74
  * BSON::UTF8
82
75
  *
@@ -471,7 +464,8 @@ static VALUE rb_integer_from_bson_int32(VALUE self, VALUE bson)
471
464
  static int64_t rb_bson_to_int64_t(VALUE bson)
472
465
  {
473
466
  uint8_t *v;
474
- uint32_t byte_0, byte_1, byte_2, byte_3;
467
+ uint32_t byte_0, byte_1;
468
+ int64_t byte_2, byte_3;
475
469
  int64_t lower, upper;
476
470
  v = (uint8_t*) RSTRING_PTR(bson);
477
471
  byte_0 = v[0];
@@ -659,7 +653,7 @@ static VALUE rb_string_to_bson_string(VALUE self, VALUE encoded)
659
653
  static VALUE rb_string_check_for_illegal_characters(VALUE self)
660
654
  {
661
655
  if (strlen(RSTRING_PTR(self)) != (size_t) RSTRING_LEN(self))
662
- rb_raise(rb_eRuntimeError, "Illegal C-String contains a null byte.");
656
+ rb_raise(rb_eArgError, "Illegal C-String contains a null byte.");
663
657
  return self;
664
658
  }
665
659
 
@@ -728,7 +722,6 @@ void Init_native()
728
722
  VALUE string = rb_const_get(bson, rb_intern("String"));
729
723
  VALUE true_class = rb_const_get(bson, rb_intern("TrueClass"));
730
724
  VALUE false_class = rb_const_get(bson, rb_intern("FalseClass"));
731
- rb_bson_binary = rb_const_get(bson, rb_intern("BINARY"));
732
725
  rb_bson_utf8_string = rb_const_get(bson, rb_intern("UTF8"));
733
726
  rb_utc_method = rb_intern("utc");
734
727
 
@@ -89,10 +89,13 @@ module BSON
89
89
  #
90
90
  # @since 2.0.0
91
91
  def to_bson(encoded = ''.force_encoding(BINARY))
92
- encode_with_placeholder_and_null(BSON_ADJUST, encoded) do |encoded|
92
+ # -1 because we are removing an extra byte
93
+ out = encode_with_placeholder_and_null(BSON_ADJUST - 1, encoded) do |encoded|
93
94
  javascript.to_bson(encoded)
94
95
  scope.to_bson(encoded)
95
96
  end
97
+ # an extra null byte has been added; we must remove it
98
+ out.chop!
96
99
  end
97
100
 
98
101
  # Deserialize a code with scope from BSON.
@@ -105,9 +108,8 @@ module BSON
105
108
  #
106
109
  # @since 2.0.0
107
110
  def self.from_bson(bson)
108
- code_with_scope = StringIO.new(bson.read(Int32.from_bson(bson)))
109
- length = code_with_scope.read(4).unpack(Int32::PACK).first
110
- new(code_with_scope.read(length).from_bson_string.chop!)
111
+ bson.read(4) # Throw away the total length.
112
+ new(bson.read(Int32.from_bson(bson)).from_bson_string.chop!, ::Hash.from_bson(bson))
111
113
  end
112
114
 
113
115
  # Register this type when the module is loaded.
@@ -31,7 +31,7 @@ module BSON
31
31
  # Get the hash as encoded BSON.
32
32
  #
33
33
  # @example Get the hash as encoded BSON.
34
- # { field: "value" }.to_bson
34
+ # { "field" => "value" }.to_bson
35
35
  #
36
36
  # @return [ String ] The encoded string.
37
37
  #
@@ -52,7 +52,7 @@ module BSON
52
52
 
53
53
  # Deserialize the hash from BSON.
54
54
  #
55
- # @param [ String ] bson The bson representing a hash.
55
+ # @param [ IO ] bson The bson representing a hash.
56
56
  #
57
57
  # @return [ Array ] The decoded hash.
58
58
  #
@@ -115,6 +115,44 @@ module BSON
115
115
  to_bson.hash
116
116
  end
117
117
 
118
+ # Get a nice string for use with object inspection.
119
+ #
120
+ # @example Inspect the object id.
121
+ # obhect_id.inspect
122
+ #
123
+ # @return [ String ] The object id in form BSON::ObjectId('id')
124
+ #
125
+ # @since 2.0.0
126
+ def inspect
127
+ "BSON::ObjectId('#{to_s}')"
128
+ end
129
+
130
+ # Dump the raw bson when calling Marshal.dump.
131
+ #
132
+ # @example Dump the raw bson.
133
+ # Marshal.dump(object_id)
134
+ #
135
+ # @return [ String ] The raw bson bytes.
136
+ #
137
+ # @since 2.0.0
138
+ def marshal_dump
139
+ to_bson
140
+ end
141
+
142
+ # Unmarshal the data into an object id.
143
+ #
144
+ # @example Unmarshal the data.
145
+ # Marshal.load(data)
146
+ #
147
+ # @param [ String ] data The raw bson bytes.
148
+ #
149
+ # @return [ String ] The raw bson bytes.
150
+ #
151
+ # @since 2.0.0
152
+ def marshal_load(data)
153
+ @raw_data = data
154
+ end
155
+
118
156
  # Get the object id as it's raw BSON data.
119
157
  #
120
158
  # @example Get the raw bson bytes.
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # Copyright (C) 2013 10gen Inc.
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -59,7 +60,6 @@ module BSON
59
60
  #
60
61
  # @since 2.0.0
61
62
  def to_bson_key(encoded = ''.force_encoding(BINARY))
62
- check_for_illegal_characters!
63
63
  to_bson_cstring(encoded)
64
64
  end
65
65
 
@@ -168,7 +168,7 @@ module BSON
168
168
 
169
169
  def check_for_illegal_characters!
170
170
  if include?(NULL_BYTE)
171
- raise RuntimeError.new("Illegal C-String '#{self}' contains a null byte.")
171
+ raise(ArgumentError, "Illegal C-String '#{self}' contains a null byte.")
172
172
  end
173
173
  end
174
174
 
@@ -55,7 +55,7 @@ module BSON
55
55
  #
56
56
  # @since 2.0.0
57
57
  def to_bson_key(encoded = ''.force_encoding(BINARY))
58
- to_s.to_bson_cstring(encoded)
58
+ to_s.to_bson_key(encoded)
59
59
  end
60
60
 
61
61
  module ClassMethods
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module BSON
16
- VERSION = "2.0.0.rc1"
16
+ VERSION = "2.0.0.rc2"
17
17
  end
@@ -40,8 +40,8 @@ describe BSON::CodeWithScope do
40
40
  end
41
41
  let(:obj) { described_class.new(code, scope) }
42
42
  let(:bson) do
43
- "#{48.to_bson}#{(code.length + 1).to_bson}#{code}#{BSON::NULL_BYTE}" +
44
- "#{scope.to_bson}#{BSON::NULL_BYTE}"
43
+ "#{47.to_bson}#{(code.length + 1).to_bson}#{code}#{BSON::NULL_BYTE}" +
44
+ "#{scope.to_bson}"
45
45
  end
46
46
 
47
47
  it_behaves_like "a bson element"
@@ -53,18 +53,22 @@ describe BSON::CodeWithScope do
53
53
  let(:type) { 15.chr }
54
54
  let(:code) { "this.value == name" }
55
55
  let(:scope) do
56
- { :name => "test" }
56
+ { "name" => "test" }
57
57
  end
58
58
  let(:obj) { described_class.new(code, scope) }
59
59
  let(:bson) { StringIO.new(obj.to_bson) }
60
- let(:deserialized) { described_class.from_bson(bson) }
60
+ let!(:deserialized) { described_class.from_bson(bson) }
61
61
 
62
62
  it "deserializes the javascript" do
63
63
  expect(deserialized.javascript).to eq(code)
64
64
  end
65
65
 
66
- it "does not deserialize a scope" do
67
- expect(deserialized.scope).to be_empty
66
+ it "deserializes the scope" do
67
+ expect(deserialized.scope).to eq(scope)
68
+ end
69
+
70
+ it "does not leave any extra bytes" do
71
+ expect(bson.read(1)).to be_nil
68
72
  end
69
73
  end
70
74
  end
@@ -383,6 +383,17 @@ describe BSON::ObjectId do
383
383
  end
384
384
  end
385
385
 
386
+ describe "#inspect" do
387
+
388
+ let(:object_id) do
389
+ described_class.new
390
+ end
391
+
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}')")
394
+ end
395
+ end
396
+
386
397
  describe ".legal?" do
387
398
 
388
399
  context "when the string is too short to be an object id" do
@@ -418,6 +429,21 @@ describe BSON::ObjectId do
418
429
  end
419
430
  end
420
431
 
432
+ describe "#marshal_dump" do
433
+
434
+ let(:object_id) do
435
+ described_class.new
436
+ end
437
+
438
+ let(:dumped) do
439
+ Marshal.dump(object_id)
440
+ end
441
+
442
+ it "dumps the raw bytes data" do
443
+ expect(Marshal.load(dumped)).to eq(object_id)
444
+ end
445
+ end
446
+
421
447
  describe "#to_bson/#from_bson" do
422
448
 
423
449
  let(:time) { Time.utc(2013, 1, 1) }
@@ -65,7 +65,7 @@ describe String do
65
65
  it "raises an error" do
66
66
  expect {
67
67
  string.to_bson_cstring
68
- }.to raise_error(RuntimeError)
68
+ }.to raise_error(ArgumentError)
69
69
  end
70
70
  end
71
71
 
@@ -41,5 +41,15 @@ describe Symbol do
41
41
  it "appends to optional previous content" do
42
42
  expect(symbol.to_bson_key(previous_content)).to eq(previous_content << encoded)
43
43
  end
44
+
45
+ context 'when the symbol contains a null byte' do
46
+ let(:symbol) { :"test#{BSON::NULL_BYTE}ing" }
47
+
48
+ it 'raises an error' do
49
+ expect {
50
+ symbol.to_bson_key
51
+ }.to raise_error(ArgumentError)
52
+ end
53
+ end
44
54
  end
45
55
  end
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.0.0.rc1
4
+ version: 2.0.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Brock
@@ -33,7 +33,7 @@ cert_chain:
33
33
  8v7zLF2XliYbfurYIwkcXs8yPn8ggApBIy9bX6VJxRs/l2+UvqzaHIFaFy/F8/GP
34
34
  RNTuXsVG5NDACo7Q
35
35
  -----END CERTIFICATE-----
36
- date: 2013-06-20 00:00:00.000000000 Z
36
+ date: 2013-09-23 00:00:00.000000000 Z
37
37
  dependencies: []
38
38
  description: A full featured BSON specification implementation, in Ruby
39
39
  email:
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: 1.3.6
130
130
  requirements: []
131
131
  rubyforge_project: bson
132
- rubygems_version: 2.0.3
132
+ rubygems_version: 2.0.6
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: Ruby Implementation of the BSON specification
metadata.gz.sig CHANGED
Binary file