Skip Menu |
 

This queue is for tickets about the Encode CPAN distribution.

Report information
The Basics
Id: 99609
Status: resolved
Priority: 0/
Queue: Encode

People
Owner: Nobody in particular
Requestors: cpan [...] chmrr.net
Cc:
AdminCc:

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

Attachments


Subject: FB_CROAK may cause decode's argument to be modified
Download (untitled) / with headers
text/plain 133b
Passing FB_CROAK to decode seems like it sometimes causes the argument to decode to be destructively modified; test attached. - Alex
Subject: encoding-argument-modified.pl
#!/usr/bin/env perl use strict; use warnings; use Encode; use Test::More; my $valid = "\x61\x00\x00\x00"; diag "This is perl $^V, Encode $Encode::VERSION"; { my $string = "$valid"; my $ret = decode( "UTF32-LE", $string, Encode::FB_DEFAULT ); is($string, $valid, "Decoding a valid string with FB_DEFAULT does not modify the provided string"); } { my $string = "$valid"; my $ret = decode( "UTF32-LE", $string, Encode::FB_CROAK ); is($string, $valid, "Decoding a valid string with FB_CROAK does not modify the provided string"); } { my $string = $valid; my $enc = find_encoding("UTF32-LE"); my $ret = $enc->decode( $string, Encode::FB_CROAK ); is($string, "\x61\x00\x00\x00", "Decoding a valid string directly via Encode::Unicode with FB_CROAK does not modify the provided string"); is($valid, "\x61\x00\x00\x00", "Decoding a valid string directly via Encode::Unicode with FB_CROAK does not modify the orginal string via COW"); } done_testing; __END__ # This is perl v5.20.0, Encode 2.63 ok 1 - Decoding a valid string with FB_DEFAULT does not modify the provided string not ok 2 - Decoding a valid string with FB_CROAK does not modify the provided string # Failed test 'Decoding a valid string with FB_CROAK does not modify the provided string' # at wat.pl line 24. # got: '' # expected: 'a' 1..2 # Looks like you failed 1 test of 2.
Download (untitled) / with headers
text/plain 374b
It's not a bug. It's a feature. Replace Encode::FB_CROAK with (Encode::FB_CROAK | Encode::LEAVE_SRC) and all of your tests pass. See Encode's pod for details. Dan the Maintainer Thereof On Tue Oct 21 01:17:39 2014, ALEXMV wrote: Show quoted text
> Passing FB_CROAK to decode seems like it sometimes causes the argument > to decode to be destructively modified; test attached. > - Alex
Subject: Re: [rt.cpan.org #99609] FB_CROAK may cause decode's argument to be modified
Date: Sat, 25 Oct 2014 00:39:27 -0400
To: bug-Encode [...] rt.cpan.org
From: Alex Vandiver <alex [...] chmrr.net>
Download (untitled) / with headers
text/plain 936b
On 10/24/2014 11:50 PM, Dan Kogai via RT wrote: Show quoted text
> It's not a bug. It's a feature. Replace Encode::FB_CROAK with > (Encode::FB_CROAK | Encode::LEAVE_SRC) and all of your tests pass. > See Encode's pod for details.
Hm -- I mis-parsed them, then. When they say: If the Encode::LEAVE_SRC bit is not set but CHECK is set, then the source string to encode() or decode() will be overwritten in place. ...I read "overwritten" to mean "replaced with the output of the encode() or decode() call." Which, upon reflection, would be rather unhelpful -- but I feel like that section can perhaps be clarified. Would it be correct to say that: If the Encode::LEAVE_SRC bit is not set but CHECK is set, then the successfully encoded or decoded parts of the source string will be set to the empty string. This is notably useful with Encode::FB_QUIET and Encode::FB_WARN. ...and would you accept a patch to that effect? - Alex


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.