Subject: | FB_CROAK may cause decode's argument to be modified |
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.