ruby beanstalk-client ruby 1.9.x and non-ascii chars

31 views
Skip to first unread message

John Mettraux

unread,
Oct 6, 2010, 2:44:35 AM10/6/10
to beansta...@googlegroups.com
Hello,

at first a great thanks for beanstalk, it's a great piece of software.

I'm using ruby and beanstalk-client (1.1.0) (beanstalkd 1.4) and I have this small piece of code :

---8<---
# encoding: UTF-8

require 'rubygems'
require 'beanstalk-client'

con = Beanstalk::Connection.new('localhost:11300')
con.put("宮島")
--->8---

On Snow Leopard, with Ruby 1.8.7-p72 and p249, no issues (program terminates without complaints).

With Ruby 1.9.1-p378 and 1.9.2-p0, I have

---8<---
/Users/jmettraux/.rvm/gems/ruby-1.9.1-p378/gems/beanstalk-client-1.1.0/lib/beanstalk-client/connection.rb:203:in `check_resp': EXPECTED_CRLF (Beanstalk::ExpectedCRLFError)
from /Users/jmettraux/.rvm/gems/ruby-1.9.1-p378/gems/beanstalk-client-1.1.0/lib/beanstalk-client/connection.rb:188:in `interact'
from /Users/jmettraux/.rvm/gems/ruby-1.9.1-p378/gems/beanstalk-client-1.1.0/lib/beanstalk-client/connection.rb:57:in `put'
from t.rb:7:in `<main>'
--->8---

Should Base64 my payload as a workaround ?


Best regards,

--
John Mettraux - http://jmettraux.wordpress.com

Keith Rarick

unread,
Oct 7, 2010, 5:21:17 PM10/7/10
to beansta...@googlegroups.com
On Wed, Oct 6, 2010 at 12:44 AM, John Mettraux <jmet...@gmail.com> wrote:
> con.put("宮島")
> ...

> /Users/jmettraux/.rvm/gems/ruby-1.9.1-p378/gems/beanstalk-client-1.1.0/lib/beanstalk-client/connection.rb:203:in `check_resp': EXPECTED_CRLF (Beanstalk::ExpectedCRLFError)

I haven't tried ruby 1.9 yet, but I expect this is a change in the
meaning of `"宮島".size`. In ruby 1.8 that method returns the number of
bytes in the string, but 1.9 (I guess) returns the number of unicode
codepoints, which can be fewer than the number of bytes.

I should be using method `bytesize` there instead of `size`.

> Should Base64 my payload as a workaround?

That would work. You should be fine as long as your payload contains
only 1-byte unicode codepoints (essentially ASCII).

kr

Reply all
Reply to author
Forward
0 new messages