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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -3
- data/ext/bson/native.c +3 -10
- data/lib/bson/code_with_scope.rb +6 -4
- data/lib/bson/hash.rb +2 -2
- data/lib/bson/object_id.rb +38 -0
- data/lib/bson/string.rb +2 -2
- data/lib/bson/symbol.rb +1 -1
- data/lib/bson/version.rb +1 -1
- data/spec/bson/code_with_scope_spec.rb +10 -6
- data/spec/bson/object_id_spec.rb +26 -0
- data/spec/bson/string_spec.rb +1 -1
- data/spec/bson/symbol_spec.rb +10 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26c195c903e73023d0f0ddbc6bd8b802965a2a32
|
4
|
+
data.tar.gz: 5a678021165a243c12330f9bc5fa8f192ea2beaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce3afab5e81c5c6179e715637693765e54fdb9d459b79684ec8210b862ec73b7940b10aa527bbf7bc9dfece19a69b01f4c86adccaadbf18f33ba5ec407cf9454
|
7
|
+
data.tar.gz: 55ebdf9995b846d805666bab644ca34df8b90d37ced302fe4eb2d921240d6a023290a84dd8ac651dac8cadcffea5a685ccb13858c90a59776d78b929c1f7b1bb
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1,3 +1 @@
|
|
1
|
-
|
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��TsG�E�"�*��'�5������̯��G�<hs��%e�A�*��������n��JQ�$��Q�`�����|�AU
|
data/ext/bson/native.c
CHANGED
@@ -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
|
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(
|
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
|
|
data/lib/bson/code_with_scope.rb
CHANGED
@@ -89,10 +89,13 @@ module BSON
|
|
89
89
|
#
|
90
90
|
# @since 2.0.0
|
91
91
|
def to_bson(encoded = ''.force_encoding(BINARY))
|
92
|
-
|
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
|
-
|
109
|
-
|
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.
|
data/lib/bson/hash.rb
CHANGED
@@ -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
|
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 [
|
55
|
+
# @param [ IO ] bson The bson representing a hash.
|
56
56
|
#
|
57
57
|
# @return [ Array ] The decoded hash.
|
58
58
|
#
|
data/lib/bson/object_id.rb
CHANGED
@@ -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.
|
data/lib/bson/string.rb
CHANGED
@@ -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
|
171
|
+
raise(ArgumentError, "Illegal C-String '#{self}' contains a null byte.")
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
data/lib/bson/symbol.rb
CHANGED
data/lib/bson/version.rb
CHANGED
@@ -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
|
-
"#{
|
44
|
-
"#{scope.to_bson}
|
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
|
-
{
|
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 "
|
67
|
-
expect(deserialized.scope).to
|
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
|
data/spec/bson/object_id_spec.rb
CHANGED
@@ -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) }
|
data/spec/bson/string_spec.rb
CHANGED
data/spec/bson/symbol_spec.rb
CHANGED
@@ -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.
|
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-
|
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.
|
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
|