Permalink
Browse files

Use 8bit bytesize for length

  • Loading branch information...
1 parent a639a9d commit b839f8d22490e65b1d964423067efc8ba6fb1790 @josh josh committed May 15, 2011
Showing with 6 additions and 1 deletion.
  1. +1 −1 lib/otnetstring.rb
  2. +5 −0 spec/otnetstring_spec.rb
View
@@ -24,7 +24,7 @@ def self.parse(io)
def self.encode(obj, string_sep = ',')
case obj
- when String then "#{obj.length}#{string_sep}#{obj}"
+ when String then "#{obj.bytesize}#{string_sep}#{obj}"
when Integer then encode(obj.inspect, '#')
when NilClass then "0~"
when Array then encode(obj.map { |e| encode(e) }.join, '[')
View
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
# Based on tnetstring-rb's spec/tnetstring_spec.rb
#
# Copyright (c) 2011 Matt Yoho
@@ -70,6 +71,10 @@
OTNetstring.encode("hello world").should == "11,hello world"
end
+ it "encodes a multibyte string" do
+ OTNetstring.encode("").should == "3,☃"
+ end
+
context "boolean" do
it "encodes true as 'true'" do
OTNetstring.encode(true).should == "4!true"

0 comments on commit b839f8d

Please sign in to comment.