Skip to content

Commit

Permalink
RUBY-947 force binary encoding for message fields
Browse files Browse the repository at this point in the history
  • Loading branch information
estolfo committed Aug 27, 2015
1 parent 2e9d132 commit 10f6750
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/mongo/protocol/serializers.rb
Expand Up @@ -74,7 +74,7 @@ module CString
# @param value [String] The string to be serialized.
# @return [String] Buffer with serialized value.
def self.serialize(buffer, value)
buffer << value
buffer << value.force_encoding(BSON::BINARY)
buffer << NULL
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mongo/server/connection.rb
Expand Up @@ -188,7 +188,7 @@ def setup_authentication!
end
end

def write(messages, buffer = '')
def write(messages, buffer = ''.force_encoding(BSON::BINARY))
start_size = 0
messages.each do |message|
message.serialize(buffer, max_bson_object_size)
Expand Down
13 changes: 13 additions & 0 deletions spec/mongo/protocol/query_spec.rb
Expand Up @@ -220,6 +220,19 @@
it 'serializes the namespace' do
expect(field).to be_cstring(ns)
end

context 'when the namespace contains unicode characters' do
let(:field) { bytes[20..40] }

let(:coll) do
'områder'
end

it 'serializes the namespace' do
expect(field).to be_cstring(ns)
end

end
end

describe 'skip' do
Expand Down
2 changes: 1 addition & 1 deletion spec/support/matchers.rb
Expand Up @@ -20,7 +20,7 @@

RSpec::Matchers.define :be_cstring do |string|
match do |actual|
actual == "#{string}\0"
actual == "#{string.force_encoding(BSON::BINARY)}\0"
end
end

Expand Down

0 comments on commit 10f6750

Please sign in to comment.