develooper Front page | perl.perl5.porters | Postings from December 2011

[perl #56340] encode() with FB_CROAK may destroy its argument

Thread Previous
From:
James E Keenan via RT
Date:
December 18, 2011 16:47
Subject:
[perl #56340] encode() with FB_CROAK may destroy its argument
Message ID:
rt-3.6.HEAD-14510-1324255646-898.56340-15-0@perl.org
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');
> 
> $enc->encode($s);
> 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? 
https://rt.perl.org/rt3/Ticket/Display.html?id=30774

Thank you very much.
Jim Keenan

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=56340

Thread Previous


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