Skip Menu |

This queue is for tickets about the AnyEvent-I3 CPAN distribution.

Report information
The Basics
Id: 55538
Status: resolved
Priority: 0/
Queue: AnyEvent-I3

People
Owner: Nobody in particular
Requestors: schmorp [...] schmorp.de
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: bytes::length doesn't return the number of bytes/octets in a scalar
Date: Sun, 14 Mar 2010 00:28:47 +0100
To: bug-anyevent-i3 [...] rt.cpan.org
From: Marc Lehmann <schmorp [...] schmorp.de>
Hi! I just had a quick look over AnyEvent::I3, and found a bug. basically, your _bytelength doesn't do what you think it does - it ignores the perl-internal encoding and returns the *internal* length in octets (not the length of it's argument in octets). this is wrong, as you later send the data over the wire (well, ae::handle), and the other side cannot know how perl encoded the scalar, so will get the wrong length. if you want the length of $payload in octets (very likely), then you need to use the normal length function, not bytes::length. (you are lucky because currently, encode_json happens to return a scalar where bytes::length and length agree - it can be wrong on user-supplied messages however). -- The choice of a Deliantra, the free code+content MORPG -----==- _GNU_ http://www.deliantra.net ----==-- _ generation ---==---(_)__ __ ____ __ Marc Lehmann --==---/ / _ \/ // /\ \/ / schmorp@schmorp.de -=====/_/_//_/\_,_/ /_/\_\
Hi Marc, Thanks for looking over my module. On Sat Mar 13 18:29:48 2010, schmorp@schmorp.de wrote: Show quoted text
> if you want the length of $payload in octets (very likely), then you need > to use the normal length function, not bytes::length.
While I do want the length of $payload in octets, I am not convinced that the normal length function does the right thing. perldoc says it returns the amount of characters in $payload, but when the payload is encoded in UTF8, this is not what I want. Any ideas? Best regards, Michael
Fixed by using encode_utf8 and length in 0.02