Skip to content

Commit

Permalink
[perl #91850] utf8::decode: croak for ro scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
Father Chrysostomos committed Jan 6, 2012
1 parent 1b3a617 commit 492ebab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/utf8.t
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,17 @@ SKIP: {
is join('', keys $h), $k2, 'utf8::decode respects copy-on-write';
}

{
# Make sure utf8::decode does not modify read-only scalars
# [perl #91850].

my $name = "\x{c3}\x{b3}";
Internals::SvREADONLY($name, 1);
eval { utf8::decode($name) };
like $@, qr/^Modification of a read-only/,
'utf8::decode respects readonliness';
}

{
my $a = "456\xb6";
utf8::upgrade($a);
Expand Down
2 changes: 1 addition & 1 deletion universal.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ XS(XS_utf8_decode)
else {
SV * const sv = ST(0);
bool RETVAL;
if (SvIsCOW(sv)) sv_force_normal(sv);
if (SvREADONLY(sv)) sv_force_normal(sv);
RETVAL = sv_utf8_decode(sv);
ST(0) = boolSV(RETVAL);
}
Expand Down

0 comments on commit 492ebab

Please sign in to comment.