forked from dankogai/p5-encode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Catch and re-issue utf8 warnings at a higher level
This catches Encode::Unicode warnings and re-issues them from Encode, so that callers can disable warnings lexically with `no warnings 'utf8'`. Fixes https://rt.cpan.org/Ticket/Display.html?id=88592
- Loading branch information
Showing
2 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use Encode; | ||
use Test::More tests => 7; | ||
|
||
my $valid = "\x61\x00\x00\x00"; | ||
my $invalid = "\x78\x56\x34\x12"; | ||
|
||
my @warnings; | ||
$SIG{__WARN__} = sub {push @warnings, "@_"}; | ||
|
||
my $enc = find_encoding("UTF32-LE"); | ||
|
||
{ | ||
@warnings = (); | ||
my $ret = Encode::Unicode::decode( $enc, $valid ); | ||
is("@warnings", "", "Calling decode in Encode::Unicode on valid string produces no warnings"); | ||
} | ||
|
||
{ | ||
@warnings = (); | ||
my $ret = Encode::Unicode::decode( $enc, $invalid ); | ||
like("@warnings", qr/is not Unicode/, "Calling decode in Encode::Unicode on invalid string warns"); | ||
} | ||
|
||
{ | ||
no warnings 'utf8'; | ||
@warnings = (); | ||
my $ret = Encode::Unicode::decode( $enc, $invalid ); | ||
is("@warnings", "", "Warning from decode in Encode::Unicode can be silenced via no warnings 'utf8'"); | ||
} | ||
|
||
{ | ||
no warnings; | ||
@warnings = (); | ||
my $ret = Encode::Unicode::decode( $enc, $invalid ); | ||
is("@warnings", "", "Warning from decode in Encode::Unicode can be silenced via no warnings"); | ||
} | ||
|
||
{ | ||
@warnings = (); | ||
my $ret = Encode::decode( $enc, $invalid ); | ||
like("@warnings", qr/is not Unicode/, "Calling decode in Encode on invalid string warns"); | ||
} | ||
|
||
{ | ||
no warnings 'utf8'; | ||
@warnings = (); | ||
my $ret = Encode::decode( $enc, $invalid ); | ||
is("@warnings", "", "Warning from decode in Encode can be silenced via no warnings 'utf8'"); | ||
}; | ||
|
||
{ | ||
no warnings; | ||
@warnings = (); | ||
my $ret = Encode::decode( $enc, $invalid ); | ||
is("@warnings", "", "Warning from decode in Encode can be silenced via no warnings 'utf8'"); | ||
}; | ||
|