Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed encoding for utf8 string in ruby 1.9

  • Loading branch information...
commit ff03a686650d9c89582b637a47b61ec34c48ae02 1 parent 5e53995
@schmurfy schmurfy authored
Showing with 14 additions and 2 deletions.
  1. +2 −2 lib/bert/encode.rb
  2. +12 −0 test/encoder_test.rb
View
4 lib/bert/encode.rb
@@ -57,7 +57,7 @@ def write_symbol(sym)
fail(sym) unless sym.is_a?(Symbol)
data = sym.to_s
write_1 ATOM
- write_2 data.length
+ write_2 data.bytesize
write_string data
end
@@ -126,7 +126,7 @@ def write_list(data)
def write_binary(data)
write_1 BIN
- write_4 data.length
+ write_4 data.bytesize
write_string data
end
View
12 test/encoder_test.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'test_helper'
class EncoderTest < Test::Unit::TestCase
@@ -78,6 +80,16 @@ class EncoderTest < Test::Unit::TestCase
assert cruby[0].instance_of?(Symbol)
assert cruby[1].instance_of?(BERT::Tuple)
end
+
+ should 'handle utf8 strings' do
+ bert = [131, 109, 0, 0, 0, 5, 195, 169, 116, 195, 169].pack('C*')
+ assert_equal bert, BERT::Encoder.encode("été")
+ end
+
+ should 'handle utf8 symbols' do
+ bert = [131, 100, 0, 5, 195, 169, 116, 195, 169].pack('C*')
+ assert_equal bert, BERT::Encoder.encode(:'été')
+ end
should "handle bignums" do
bert = [131,110,8,0,0,0,232,137,4,35,199,138].pack('c*')
Please sign in to comment.
Something went wrong with that request. Please try again.