bson 2.0.0.rc1-java → 2.0.0.rc2-java

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.

data.tar.gz.sig CHANGED
Binary file
data/Rakefile CHANGED
@@ -81,8 +81,13 @@ end
81
81
  task :release => :build do
82
82
  system "git tag -a v#{BSON::VERSION} -m 'Tagging release: #{BSON::VERSION}'"
83
83
  system "git push --tags"
84
- system "gem push bson-#{BSON::VERSION}.gem"
85
- system "rm bson-#{BSON::VERSION}.gem"
84
+ if jruby?
85
+ system "gem push bson-#{BSON::VERSION}-java.gem"
86
+ system "rm bson-#{BSON::VERSION}-java.gem"
87
+ else
88
+ system "gem push bson-#{BSON::VERSION}.gem"
89
+ system "rm bson-#{BSON::VERSION}.gem"
90
+ end
86
91
  end
87
92
 
88
93
  namespace :benchmark do
Binary file
@@ -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
@@ -2,7 +2,7 @@
2
2
  name: bson
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 2.0.0.rc1
5
+ version: 2.0.0.rc2
6
6
  platform: java
7
7
  authors:
8
8
  - Tyler Brock
@@ -34,7 +34,7 @@ cert_chain:
34
34
  8v7zLF2XliYbfurYIwkcXs8yPn8ggApBIy9bX6VJxRs/l2+UvqzaHIFaFy/F8/GP
35
35
  RNTuXsVG5NDACo7Q
36
36
  -----END CERTIFICATE-----
37
- date: 2013-06-20 00:00:00.000000000 Z
37
+ date: 2013-09-23 00:00:00.000000000 Z
38
38
  dependencies: []
39
39
  description: A full featured BSON specification implementation, in Ruby
40
40
  email:
@@ -117,13 +117,13 @@ require_paths:
117
117
  - lib
118
118
  required_ruby_version: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - ">="
120
+ - - '>='
121
121
  - !ruby/object:Gem::Version
122
122
  version: 1.8.7
123
123
  none: false
124
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  requirements:
126
- - - ">="
126
+ - - '>='
127
127
  - !ruby/object:Gem::Version
128
128
  version: 1.3.6
129
129
  none: false
metadata.gz.sig CHANGED
Binary file