develooper Front page | perl.perl5.porters | Postings from January 2012

Re: pack and ASCII

Thread Previous | Thread Next
From:
Eric Brine
Date:
January 15, 2012 14:01
Subject:
Re: pack and ASCII
Message ID:
CALJW-qH_8iJk_zcnyV8L9U-+V1vQiSOMpzPaquYQUzM5Q3wTZA@mail.gmail.com
[Ignore my previous message. It was sent while I was still composing it.]

On Sat, Jan 14, 2012 at 11:11 AM, Jesse Luehrs <doy@tozt.net> wrote:

> 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



I agree with everything you said here. I cannot think of a use for C<< pack
"N/A*" >>.

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.
>

So you're saying "A" should warn when it's combined with some other formats
and the resulting string has characters above 255?

It's possible. The redundancy of the warning makes the change of little
use, and it doesn't help modules that use SvPV without checking SvUTF8 at
all, but it's possible.

- Eric

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About