From 492ebabafba699f4c29cfd76c551ec1f342f08e9 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Thu, 5 Jan 2012 16:47:54 -0800 Subject: [PATCH] [perl #91850] utf8::decode: croak for ro scalars --- lib/utf8.t | 11 +++++++++++ universal.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/utf8.t b/lib/utf8.t index b13bb5377d65..e56eebf626df 100644 --- a/lib/utf8.t +++ b/lib/utf8.t @@ -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); diff --git a/universal.c b/universal.c index 9d743abaaa1e..dd8ae74372f4 100644 --- a/universal.c +++ b/universal.c @@ -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); }