chrisroberts / krakow

Ruby client library for NSQ
Other
99 stars 17 forks source link

PUB command assumes that its message contains only 8-bit characters #24

Closed fionawhim closed 9 years ago

fionawhim commented 9 years ago

Inside of pub.rb, the binary size of the message is taken by doing a .length on the string before it is packed into its array. This means that the header contains the character length of the string, not necessarily its length in bytes.

So, if a value is passed to Pub whose string representation contains multibyte characters, Krakow will report an incorrect size.

irb(main):020:0> "€".length
=> 1
irb(main):021:0> ["€"].pack("a*").length
=> 3

I believe this holds true of other commands (certainly mpub).

Let me know if you'd like me to try and put a PR together for this.

chrisroberts commented 9 years ago

Nice catch. :+1:

Updated all instances of this (using the String#bytesize method)