Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninitialized value fixes #122

Merged
merged 3 commits into from
Sep 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Encode/CN/HZ.pm
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ sub encode($$;$) {
}
elsif ( $str =~ s/(.)// ) {
my $s = $1;
my $tmp = $GB->encode( $s, $chk );
my $tmp = $GB->encode( $s, $chk || 0 );
last if !defined $tmp;
if ( length $tmp == 2 ) { # maybe a valid GB char (XXX)
if ($in_ascii) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Encode/JP/JIS7.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ sub encode($$;$) {
# empty the input string in the stack so perlio is ok
$_[1] = '' if $chk;
my ( $h2z, $jis0212 ) = @$obj{qw(h2z jis0212)};
my $octet = Encode::encode( 'euc-jp', $utf8, $chk );
my $octet = Encode::encode( 'euc-jp', $utf8, $chk || 0 );
$h2z and &Encode::JP::H2Z::h2z( \$octet );
euc_jis( \$octet, $jis0212 );
return $octet;
Expand Down
21 changes: 12 additions & 9 deletions lib/Encode/MIME/Header.pm
Original file line number Diff line number Diff line change
Expand Up @@ -128,26 +128,26 @@ sub decode($$;$) {
}

if ( not defined $enc ) {
Carp::croak qq(Unknown charset "$charset") if not ref $chk and $chk & Encode::DIE_ON_ERR;
Carp::carp qq(Unknown charset "$charset") if not ref $chk and $chk & Encode::WARN_ON_ERR;
$stop = 1 if not ref $chk and $chk & Encode::RETURN_ON_ERR;
Carp::croak qq(Unknown charset "$charset") if not ref $chk and $chk and $chk & Encode::DIE_ON_ERR;
Carp::carp qq(Unknown charset "$charset") if not ref $chk and $chk and $chk & Encode::WARN_ON_ERR;
$stop = 1 if not ref $chk and $chk and $chk & Encode::RETURN_ON_ERR;
$output .= ($output =~ /(?:\A|[ \t])$/ ? '' : ' ') . $orig unless $stop; # $orig mime word is separated by whitespace
$stop ? $orig : '';
} else {
if ( uc($mime_enc) eq 'B' and $obj->{decode_b} ) {
my $decoded = _decode_b($enc, $text, $chk);
$stop = 1 if not defined $decoded and not ref $chk and $chk & Encode::RETURN_ON_ERR;
$stop = 1 if not defined $decoded and not ref $chk and $chk and $chk & Encode::RETURN_ON_ERR;
$output .= (defined $decoded ? $decoded : $text) unless $stop;
$stop ? $orig : '';
} elsif ( uc($mime_enc) eq 'Q' and $obj->{decode_q} ) {
my $decoded = _decode_q($enc, $text, $chk);
$stop = 1 if not defined $decoded and not ref $chk and $chk & Encode::RETURN_ON_ERR;
$stop = 1 if not defined $decoded and not ref $chk and $chk and $chk & Encode::RETURN_ON_ERR;
$output .= (defined $decoded ? $decoded : $text) unless $stop;
$stop ? $orig : '';
} else {
Carp::croak qq(MIME "$mime_enc" unsupported) if not ref $chk and $chk & Encode::DIE_ON_ERR;
Carp::carp qq(MIME "$mime_enc" unsupported) if not ref $chk and $chk & Encode::WARN_ON_ERR;
$stop = 1 if not ref $chk and $chk & Encode::RETURN_ON_ERR;
Carp::croak qq(MIME "$mime_enc" unsupported) if not ref $chk and $chk and $chk & Encode::DIE_ON_ERR;
Carp::carp qq(MIME "$mime_enc" unsupported) if not ref $chk and $chk and $chk & Encode::WARN_ON_ERR;
$stop = 1 if not ref $chk and $chk and $chk & Encode::RETURN_ON_ERR;
$output .= ($output =~ /(?:\A|[ \t])$/ ? '' : ' ') . $orig unless $stop; # $orig mime word is separated by whitespace
$stop ? $orig : '';
}
Expand Down Expand Up @@ -198,6 +198,7 @@ sub _decode_q {

sub _decode_octets {
my ($enc, $octets, $chk) = @_;
$chk = 0 unless defined $chk;
$chk &= ~Encode::LEAVE_SRC if not ref $chk and $chk;
my $output = $enc->decode($octets, $chk);
return undef if not ref $chk and $chk and $octets ne '';
Expand Down Expand Up @@ -238,7 +239,9 @@ sub _encode_string {
my ($obj, $str, $chk) = @_;
my $wordlen = $obj->{bpl} > 76 ? 76 : $obj->{bpl};
my $enc = Encode::find_mime_encoding($obj->{charset});
my $enc_chk = (not ref $chk and $chk) ? ($chk | Encode::LEAVE_SRC) : $chk;
my $enc_chk = $chk;
$enc_chk = 0 unless defined $enc_chk;
$enc_chk |= Encode::LEAVE_SRC if not ref $enc_chk and $enc_chk;
my @result = ();
my $octets = '';
while ( length( my $chr = substr($str, 0, 1, '') ) ) {
Expand Down
2 changes: 2 additions & 0 deletions t/decode.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
use strict;
use Encode qw(decode_utf8 FB_CROAK find_encoding decode);
use Test::More tests => 17;
use Test::Builder;

sub croak_ok(&) {
local $Test::Builder::Level = $Test::Builder::Level + 1;
my $code = shift;
eval { $code->() };
like $@, qr/does not map/;
Expand Down