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

Disable _utf8_on and _utf8_off for tainted values #74

Merged
merged 1 commit into from
Oct 28, 2016
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
4 changes: 2 additions & 2 deletions Encode.xs
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ SV * sv
CODE:
{
SvGETMAGIC(sv);
if (SvPOKp(sv)) {
if (!SvTAINTED(sv) && SvPOKp(sv)) {
if (SvTHINKFIRST(sv)) sv_force_normal(sv);
RETVAL = newSViv(SvUTF8(sv));
SvUTF8_on(sv);
Expand All @@ -1004,7 +1004,7 @@ SV * sv
CODE:
{
SvGETMAGIC(sv);
if (SvPOKp(sv)) {
if (!SvTAINTED(sv) && SvPOKp(sv)) {
if (SvTHINKFIRST(sv)) sv_force_normal(sv);
RETVAL = newSViv(SvUTF8(sv));
SvUTF8_off(sv);
Expand Down
6 changes: 5 additions & 1 deletion t/taint.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ my $notaint = "";
my $notaint_str = "dan\x{5f3e}" . $notaint;
my $notaint_bin = encode('UTF-8', $notaint_str);
my @names = Encode->encodings(':all');
plan tests => 4 * @names;
plan tests => 4 * @names + 2;
for my $name (@names) {
my ($d, $e, $s);
eval {
Expand Down Expand Up @@ -47,3 +47,7 @@ for my $name (@names) {
ok ! tainted($d), "decode $name";
}
}
Encode::_utf8_on($bin);
ok(!Encode::is_utf8($bin), "Encode::_utf8_on does not work on tainted values");
Encode::_utf8_off($str);
ok(Encode::is_utf8($str), "Encode::_utf8_off does not work on tainted values");