Front page | perl.perl5.porters |
Postings from January 2012
Re: pack and ASCII
Thread Previous
|
Thread Next
From:
Jesse Luehrs
Date:
January 14, 2012 08:11
Subject:
Re: pack and ASCII
Message ID:
20120114161123.GX23629@tozt.net
On Sat, Jan 14, 2012 at 02:47:07AM -0500, Eric Brine wrote:
> I said C<pack> should always downgrade its output. I was most definitely
> including C<< pack "N/A*" >> and C<< pack "N/A*" >> in my statement.
>
> So yes, you did ask me if I meant that the output of C<< pack "N" >> should
> be encoded.
>
> And no, that would be stupid.
But this is *exactly* my point. There is no useful behavior that
pack('N/A*', $text) can do at all. If the resulting string has the UTF8
flag set, then the length will be interpreted as part of the utf8
sequence, which is broken. If it doesn't, then the text will be a
utf8-encoded byte string, which is also broken. If pack chooses one of
the two of those behaviors based on whether or not $text has non-ASCII
characters in it, that's orders of magnitude worse. The only way for
this to be correct is if this format is only ever passed an
already-encoded byte string, and the result is also treated as a byte
string. Passing non-ASCII characters to pack (or at least, to a format
like 'A') should be caught as an error *when you do that*, not just
something that does the wrong thing silently.
-doy
Thread Previous
|
Thread Next