On Wed Jun 25 06:07:14 2008, kappa wrote:
Standard Encode::encode() function with non-FB_DEFAULT argument
and 'utf-7' encoding always kills its data argument.

use Encode;

my $s = 'test';
my $s2 = $s;

my $enc = find_encoding('utf-7');

warn "encode '$s' ne '$s2'\n" if $s ne $s2;

$enc->encode($s, Encode::FB_CROAK | Encode::LEAVE_SRC);
warn "encode w. FB_CROAK '$s' ne '$s2'\n" if $s ne $s2;

Encode POD suggests using LEAVE_SRC bit, but it's not used inside
utf-7 codec so it has no effect.

Here's a patch against bleadperl as of today:

--- UTF7.pm.orig 2008-06-25 16:25:57.000000000 +0400
+++ UTF7.pm 2008-06-25 17:01:58.000000000 +0400
@@ -52,7 +52,7 @@
die "This should not happen! (pos=" . pos($str) . ")";
- $_[1] = '' if $chk;
+ $_[1] = '' if $chk && ($chk & Encode::LEAVE_SRC) == 0;
return $bytes;
Is this the same issue that was addressed in
https://rt.perl.org/rt3/Ticket/Display.html?id=22834 (closed in 2003)?

And, since we're on the subject of Encode and FB_CROAK, is it related to
this ticket still open since 2004?

Thank you very much.
Jim Keenan

via perlbug: queue: perl5 status: new

Search Discussions

  • Ricardo SIGNES via RT at Dec 19, 2011 at 2:11 am
    This bug is *NOT* the same as

    It does not appear to be related to

    The problem APPEARS to be that the user is relying on the $check
    semantics from Encode::encode, which do not APPEAR to be the same as
    those of an Encode::Encoding object's ->encode method. There, $check
    seems to be a simple boolean and any true value for $check means that
    the code should-or-must alter the given string in place.

    The following simplified test passes, showing that the semantics for
    $check in the function do seem to work as promised:

    use Encode;
    my $s = 'test';
    my $s2 = $s;
    encode('utf-7', $s, Encode::FB_CROAK | Encode::LEAVE_SRC );
    warn "encode w. FB_CROAK '$s' ne '$s2'\n" if $s ne $s2;

    I believe this is a non-bug.

    via perlbug: queue: perl5 status: open

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl5-porters @
postedDec 19, '11 at 12:47a
activeDec 19, '11 at 2:11a

1 user in discussion

Ricardo SIGNES via RT: 2 posts



site design / logo © 2022 Grokbase