bson 1.1.5 → 1.2.rc0

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.

@@ -2,15 +2,21 @@
2
2
 
3
3
  $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
4
 
5
- MINIMUM_BSON_EXT_VERSION = "1.1.5"
5
+ MINIMUM_BSON_EXT_VERSION = "1.2.rc0"
6
6
 
7
7
  module BSON
8
- VERSION = "1.1.5"
8
+ VERSION = "1.2.rc0"
9
+
10
+ if defined? Mongo::DEFAULT_MAX_BSON_SIZE
11
+ DEFAULT_MAX_BSON_SIZE = Mongo::DEFAULT_MAX_BSON_SIZE
12
+ else
13
+ DEFAULT_MAX_BSON_SIZE = 4 * 1024 * 1024
14
+ end
15
+
9
16
  def self.serialize(obj, check_keys=false, move_id=false)
10
17
  BSON_CODER.serialize(obj, check_keys, move_id)
11
18
  end
12
19
 
13
-
14
20
  def self.deserialize(buf=nil)
15
21
  BSON_CODER.deserialize(buf)
16
22
  end
@@ -34,7 +40,7 @@ end
34
40
 
35
41
  if RUBY_PLATFORM =~ /java/
36
42
  jar_dir = File.join(File.dirname(__FILE__), '..', 'ext', 'java', 'jar')
37
- require File.join(jar_dir, 'mongo-2.2.jar')
43
+ require File.join(jar_dir, 'mongo-2.4.jar')
38
44
  require File.join(jar_dir, 'bson-2.2.jar')
39
45
  require File.join(jar_dir, 'jbson.jar')
40
46
  require 'bson/bson_java'
@@ -47,7 +53,7 @@ else
47
53
  raise LoadError if ENV['TEST_MODE'] && !ENV['C_EXT']
48
54
 
49
55
  # Raise LoadError unless little endian
50
- raise LoadError unless [1,0,0,0].pack("i").bytes.first == 1
56
+ raise LoadError unless "\x01\x00\x00\x00".unpack("i").first == 1
51
57
 
52
58
  require 'bson_ext/cbson'
53
59
  raise LoadError unless defined?(CBson::VERSION)
@@ -28,5 +28,12 @@ module BSON
28
28
  CBson.deserialize(ByteBuffer.new(buf).to_s)
29
29
  end
30
30
 
31
+ def self.max_bson_size
32
+ CBson.max_bson_size
33
+ end
34
+
35
+ def self.update_max_bson_size(connection)
36
+ CBson.update_max_bson_size(connection)
37
+ end
31
38
  end
32
39
  end
@@ -17,5 +17,12 @@ module BSON
17
17
  callback.get
18
18
  end
19
19
 
20
+ def self.max_bson_size
21
+ Java::OrgJbson::RubyBSONEncoder.max_bson_size(self)
22
+ end
23
+
24
+ def self.update_max_bson_size(connection)
25
+ Java::OrgJbson::RubyBSONEncoder.update_max_bson_size(self, connection)
26
+ end
20
27
  end
21
28
  end
@@ -20,6 +20,10 @@ module BSON
20
20
  # A BSON seralizer/deserializer in pure Ruby.
21
21
  class BSON_RUBY
22
22
 
23
+ DEFAULT_MAX_BSON_SIZE = 4 * 1024 * 1024
24
+
25
+ @@max_bson_size = DEFAULT_MAX_BSON_SIZE
26
+
23
27
  MINKEY = -1
24
28
  EOO = 0
25
29
  NUMBER = 1
@@ -51,13 +55,13 @@ module BSON
51
55
  NULL_BYTE = "\0".force_encoding('binary').freeze
52
56
  UTF8_ENCODING = Encoding.find('utf-8')
53
57
  BINARY_ENCODING = Encoding.find('binary')
54
-
58
+
55
59
  def self.to_utf8_binary(str)
56
60
  str.encode(UTF8_ENCODING).force_encoding(BINARY_ENCODING)
57
61
  end
58
62
  else
59
63
  NULL_BYTE = "\0"
60
-
64
+
61
65
  def self.to_utf8_binary(str)
62
66
  begin
63
67
  str.unpack("U*")
@@ -68,6 +72,14 @@ module BSON
68
72
  end
69
73
  end
70
74
 
75
+ def self.update_max_bson_size(connection)
76
+ @@max_bson_size = connection.max_bson_size
77
+ end
78
+
79
+ def self.max_bson_size
80
+ @@max_bson_size
81
+ end
82
+
71
83
  def self.serialize_cstr(buf, val)
72
84
  buf.put_binary(to_utf8_binary(val.to_s))
73
85
  buf.put_binary(NULL_BYTE)
@@ -120,8 +132,8 @@ module BSON
120
132
  end
121
133
 
122
134
  serialize_eoo_element(@buf)
123
- if @buf.size > 4 * 1024 * 1024
124
- raise InvalidDocument, "Document is too large (#{@buf.size}). BSON documents are limited to 4MB (#{4 * 1024 * 1024})."
135
+ if @buf.size > @@max_bson_size
136
+ raise InvalidDocument, "Document is too large (#{@buf.size}). BSON documents are limited to #{@@max_bson_size} bytes."
125
137
  end
126
138
  @buf.put_int(@buf.size, 0)
127
139
  @buf
@@ -322,11 +334,11 @@ module BSON
322
334
  def deserialize_regex_data(buf)
323
335
  str = deserialize_cstr(buf)
324
336
  options_str = deserialize_cstr(buf)
325
- options = 0
326
- options |= Regexp::IGNORECASE if options_str.include?('i')
327
- options |= Regexp::MULTILINE if options_str.include?('m')
328
- options |= Regexp::EXTENDED if options_str.include?('x')
329
- Regexp.new(str, options)
337
+ opts = 0
338
+ opts |= Regexp::IGNORECASE if options_str.include?('i')
339
+ opts |= Regexp::MULTILINE if options_str.include?('m')
340
+ opts |= Regexp::EXTENDED if options_str.include?('x')
341
+ Regexp.new(str, opts)
330
342
  end
331
343
 
332
344
  def encoded_str(str)
@@ -67,13 +67,26 @@ class BSONTest < Test::Unit::TestCase
67
67
  assert_doc_pass(doc)
68
68
  end
69
69
 
70
- def test_document_length
71
- doc = {'name' => 'a' * 5 * 1024 * 1024}
70
+ def test_limit_max_bson_size
71
+ doc = {'name' => 'a' * BSON_CODER.max_bson_size}
72
72
  assert_raise InvalidDocument do
73
73
  assert @encoder.serialize(doc)
74
74
  end
75
75
  end
76
76
 
77
+ def test_max_bson_size
78
+ assert BSON_CODER.max_bson_size >= BSON::DEFAULT_MAX_BSON_SIZE
79
+ end
80
+
81
+ def test_update_max_bson_size
82
+ require 'ostruct'
83
+ mock_conn = OpenStruct.new
84
+ size = 7 * 1024 * 1024
85
+ mock_conn.max_bson_size = size
86
+ assert_equal size, BSON_CODER.update_max_bson_size(mock_conn)
87
+ assert_equal size, BSON_CODER.max_bson_size
88
+ end
89
+
77
90
  def test_round_trip
78
91
  doc = {'doc' => 123}
79
92
  @encoder.deserialize(@encoder.serialize(doc))
@@ -200,6 +213,15 @@ class BSONTest < Test::Unit::TestCase
200
213
  assert_doc_pass(doc)
201
214
  end
202
215
 
216
+ def test_array_keys
217
+ doc = {'doc' => [1, 2, 'a', 'b']}
218
+ bson = @encoder.serialize(doc).to_a
219
+ assert_equal 48, bson[14]
220
+ assert_equal 49, bson[21]
221
+ assert_equal 50, bson[28]
222
+ assert_equal 51, bson[37]
223
+ end
224
+
203
225
  def test_regex
204
226
  doc = {'doc' => /foobar/i}
205
227
  assert_doc_pass(doc)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bson
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
4
+ hash: 977940448
5
+ prerelease: true
6
6
  segments:
7
7
  - 1
8
- - 1
9
- - 5
10
- version: 1.1.5
8
+ - 2
9
+ - rc0
10
+ version: 1.2.rc0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jim Menard
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-12-15 00:00:00 -05:00
20
+ date: 2011-01-05 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies: []
23
23
 
@@ -31,8 +31,6 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
 
33
33
  files:
34
- - Rakefile
35
- - bson.gemspec
36
34
  - LICENSE.txt
37
35
  - lib/bson.rb
38
36
  - lib/bson/bson_ruby.rb
@@ -48,10 +46,6 @@ files:
48
46
  - lib/bson/bson_java.rb
49
47
  - bin/b2json
50
48
  - bin/j2bson
51
- - ext/java/jar/jruby.jar
52
- - ext/java/jar/mongo-2.2.jar
53
- - ext/java/jar/bson-2.2.jar
54
- - ext/java/jar/jbson.jar
55
49
  - test/bson/byte_buffer_test.rb
56
50
  - test/bson/binary_test.rb
57
51
  - test/bson/object_id_test.rb
@@ -80,12 +74,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
74
  required_rubygems_version: !ruby/object:Gem::Requirement
81
75
  none: false
82
76
  requirements:
83
- - - ">="
77
+ - - ">"
84
78
  - !ruby/object:Gem::Version
85
- hash: 3
79
+ hash: 25
86
80
  segments:
87
- - 0
88
- version: "0"
81
+ - 1
82
+ - 3
83
+ - 1
84
+ version: 1.3.1
89
85
  requirements: []
90
86
 
91
87
  rubyforge_project:
data/Rakefile DELETED
@@ -1,194 +0,0 @@
1
- # -*- mode: ruby; -*-
2
- require 'rubygems'
3
- require 'rubygems/specification'
4
- require 'fileutils'
5
- require 'rake'
6
- require 'rake/testtask'
7
- require 'rake/gempackagetask'
8
- begin
9
- require 'rake/contrib/rubyforgepublisher'
10
- rescue LoadError
11
- end
12
- require 'rbconfig'
13
- include Config
14
- ENV['TEST_MODE'] = 'TRUE'
15
-
16
- task :java do
17
- Rake::Task['build:java'].invoke
18
- Rake::Task['test:ruby'].invoke
19
- end
20
-
21
- namespace :build do
22
- desc "Build the java extensions."
23
- task :java do
24
- puts "Building Java extensions..."
25
- java_dir = File.join(File.dirname(__FILE__), 'ext', 'java')
26
- jar_dir = File.join(java_dir, 'jar')
27
-
28
- jruby_jar = File.join(jar_dir, 'jruby.jar')
29
- mongo_jar = File.join(jar_dir, 'mongo-2.2.jar')
30
- bson_jar = File.join(jar_dir, 'bson-2.2.jar')
31
-
32
- src_base = File.join(java_dir, 'src')
33
-
34
- system("javac -Xlint:unchecked -classpath #{jruby_jar}:#{mongo_jar}:#{bson_jar} #{File.join(src_base, 'org', 'jbson', '*.java')}")
35
- system("cd #{src_base} && jar cf #{File.join(jar_dir, 'jbson.jar')} #{File.join('.', 'org', 'jbson', '*.class')}")
36
- end
37
- end
38
-
39
- desc "Test the MongoDB Ruby driver."
40
- task :test do
41
- puts "\nTo test the driver with the C-extensions:\nrake test:c\n\n"
42
- puts "To test the pure ruby driver: \nrake test:ruby\n\n"
43
- end
44
-
45
- namespace :test do
46
-
47
- desc "Test the driver with the C extension enabled."
48
- task :c do
49
- ENV['C_EXT'] = 'TRUE'
50
- if ENV['TEST']
51
- Rake::Task['test:functional'].invoke
52
- else
53
- Rake::Task['test:unit'].invoke
54
- Rake::Task['test:functional'].invoke
55
- Rake::Task['test:bson'].invoke
56
- Rake::Task['test:pooled_threading'].invoke
57
- Rake::Task['test:drop_databases'].invoke
58
- end
59
- ENV['C_EXT'] = nil
60
- end
61
-
62
- desc "Test the driver using pure ruby (no C extension)"
63
- task :ruby do
64
- ENV['C_EXT'] = nil
65
- if ENV['TEST']
66
- Rake::Task['test:functional'].invoke
67
- else
68
- Rake::Task['test:unit'].invoke
69
- Rake::Task['test:functional'].invoke
70
- Rake::Task['test:bson'].invoke
71
- Rake::Task['test:pooled_threading'].invoke
72
- Rake::Task['test:drop_databases'].invoke
73
- end
74
- end
75
-
76
- desc "Run the replica set test suite"
77
- Rake::TestTask.new(:rs) do |t|
78
- t.test_files = FileList['test/replica_sets/*_test.rb']
79
- t.verbose = true
80
- end
81
-
82
- Rake::TestTask.new(:unit) do |t|
83
- t.test_files = FileList['test/unit/*_test.rb']
84
- t.verbose = true
85
- end
86
-
87
- Rake::TestTask.new(:functional) do |t|
88
- t.test_files = FileList['test/*_test.rb']
89
- t.verbose = true
90
- end
91
-
92
- Rake::TestTask.new(:pooled_threading) do |t|
93
- t.test_files = FileList['test/threading/*_test.rb']
94
- t.verbose = true
95
- end
96
-
97
- Rake::TestTask.new(:auto_reconnect) do |t|
98
- t.test_files = FileList['test/auxillary/autoreconnect_test.rb']
99
- t.verbose = true
100
- end
101
-
102
- Rake::TestTask.new(:authentication) do |t|
103
- t.test_files = FileList['test/auxillary/authentication_test.rb']
104
- t.verbose = true
105
- end
106
-
107
- Rake::TestTask.new(:new_features) do |t|
108
- t.test_files = FileList['test/auxillary/1.4_features.rb']
109
- t.verbose = true
110
- end
111
-
112
- Rake::TestTask.new(:bson) do |t|
113
- t.test_files = FileList['test/bson/*_test.rb']
114
- t.verbose = true
115
- end
116
-
117
- task :drop_databases do |t|
118
- puts "Dropping test databases..."
119
- require './lib/mongo'
120
- con = Mongo::Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
121
- ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Connection::DEFAULT_PORT)
122
- con.database_names.each do |name|
123
- con.drop_database(name) if name =~ /^ruby-test/
124
- end
125
- end
126
- end
127
-
128
- desc "Generate RDOC documentation"
129
- task :rdoc do
130
- version = eval(File.read("mongo.gemspec")).version
131
- out = File.join('html', version.to_s)
132
- FileUtils.rm_rf('html')
133
- system "rdoc --main README.md --op #{out} --inline-source --quiet README.md `find lib -name '*.rb'`"
134
- end
135
-
136
- desc "Generate YARD documentation"
137
- task :ydoc do
138
- require File.join(File.dirname(__FILE__), 'lib', 'mongo')
139
- out = File.join('ydoc', Mongo::VERSION)
140
- FileUtils.rm_rf('ydoc')
141
- system "yardoc lib/**/*.rb lib/mongo/**/*.rb lib/bson/**/*.rb -e yard/yard_ext.rb -p yard/templates -o #{out} --title MongoRuby-#{Mongo::VERSION} --files docs/TUTORIAL.md,docs/GridFS.md,docs/FAQ.md,docs/REPLICA_SETS.md,docs/WRITE_CONCERN.md,docs/HISTORY.md,docs/CREDITS.md,docs/1.0_UPGRADE.md"
142
- end
143
-
144
- namespace :bamboo do
145
- namespace :test do
146
- task :ruby do
147
- Rake::Task['test:ruby'].invoke
148
- end
149
-
150
- task :c do
151
- Rake::Task['gem:install_extensions'].invoke
152
- Rake::Task['test:c'].invoke
153
- end
154
- end
155
- end
156
-
157
- namespace :gem do
158
-
159
- desc "Install the gem locally"
160
- task :install do
161
- sh "gem build bson.gemspec"
162
- sh "gem install --no-rdoc --no-ri bson-*.gem"
163
-
164
- sh "gem build mongo.gemspec"
165
- sh "gem install --no-rdoc --no-ri mongo-*.gem"
166
-
167
- sh "rm mongo-*.gem"
168
- sh "rm bson-*.gem"
169
- end
170
-
171
- desc "Install the optional c extensions"
172
- task :install_extensions do
173
- sh "gem build bson_ext.gemspec"
174
- sh "gem install --no-rdoc --no-ri bson_ext-*.gem"
175
- sh "rm bson_ext-*.gem"
176
- end
177
-
178
- end
179
-
180
- namespace :ci do
181
- namespace :test do
182
- task :c do
183
- Rake::Task['gem:install'].invoke
184
- Rake::Task['gem:install_extensions'].invoke
185
- Rake::Task['test:c'].invoke
186
- end
187
- end
188
- end
189
-
190
- task :default => :list
191
-
192
- task :list do
193
- system 'rake -T'
194
- end
@@ -1,27 +0,0 @@
1
- require "./lib/bson"
2
-
3
- Gem::Specification.new do |s|
4
- s.name = 'bson'
5
-
6
- s.version = BSON::VERSION
7
-
8
- s.platform = Gem::Platform::RUBY
9
- s.summary = 'Ruby implementation of BSON'
10
- s.description = 'A Ruby BSON implementation for MongoDB. For more information about Mongo, see http://www.mongodb.org. For more information on BSON, see http://www.bsonspec.org.'
11
-
12
- s.require_paths = ['lib']
13
-
14
- s.files = ['Rakefile', 'bson.gemspec', 'LICENSE.txt']
15
- s.files += ['lib/bson.rb'] + Dir['lib/bson/**/*.rb']
16
- s.files += ['bin/b2json', 'bin/j2bson']
17
- s.files += Dir['ext/java/jar/**/*.jar']
18
- s.test_files = Dir['test/bson/*.rb']
19
-
20
- s.executables = ['b2json', 'j2bson']
21
-
22
- s.has_rdoc = true
23
-
24
- s.authors = ['Jim Menard', 'Mike Dirolf', 'Kyle Banker']
25
- s.email = 'mongodb-dev@googlegroups.com'
26
- s.homepage = 'http://www.mongodb.org'
27
- end
Binary file
Binary file
Binary file
Binary file