Skip to content

Commit

Permalink
Merge pull request #57 from protobuf-ruby/bk-string-utf8
Browse files Browse the repository at this point in the history
Problem with the UTF-8 encoding
  • Loading branch information
bkerley committed Sep 5, 2014
2 parents 7853a10 + 13575bf commit 028d611
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
7 changes: 5 additions & 2 deletions lib/beefcake/buffer/decode.rb
Expand Up @@ -12,10 +12,13 @@ def read_info
[fn, wire]
end

def read_string
def read_bytes
read(read_uint64)
end
alias :read_bytes :read_string

def read_string
read_bytes.force_encoding Encoding.find('utf-8')
end

def read_fixed32
bytes = read(4)
Expand Down
4 changes: 3 additions & 1 deletion test/buffer_decode_test.rb
Expand Up @@ -19,7 +19,9 @@ def test_read_info

def test_read_string
@buf.append_string("testing")
assert_equal "testing", @buf.read_string
decoded = @buf.read_string
assert_equal "testing", decoded
assert_equal Encoding.find('utf-8'), decoded.encoding
end

def test_read_fixed32
Expand Down
8 changes: 3 additions & 5 deletions test/generator_test.rb
Expand Up @@ -10,11 +10,9 @@ def setup
@req = CodeGeneratorRequest.decode(mock_request)
end

if "".respond_to?(:encoding)
def test_request_has_filenames_as_binary
@req.proto_file.each do |file|
assert_equal Encoding.find("ASCII-8BIT"), file.name.encoding
end
def test_request_has_filenames_as_string
@req.proto_file.each do |file|
assert_equal Encoding.find("UTF-8"), file.name.encoding
end
end

Expand Down

0 comments on commit 028d611

Please sign in to comment.