summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2010-09-16 14:07:50 +0200
committerRafael Garcia-Suarez <rgs@consttype.org>2010-09-16 14:07:50 +0200
commit83c555564918110c20f99f55c77d9dfc27f217fb (patch)
tree31c5fd2e85ae42e4d1d88c89b6060a98f8dc018f
parent95961f2bb1706f8782e09e22425d5958169ef5cd (diff)
downloadperl-83c555564918110c20f99f55c77d9dfc27f217fb.tar.gz
Fix warn to respect utf8-encoded scalars [perl #45549]
-rw-r--r--t/op/warn.t26
-rw-r--r--util.c4
2 files changed, 26 insertions, 4 deletions
diff --git a/t/op/warn.t b/t/op/warn.t
index 571dfb011c..5f4e04e9a5 100644
--- a/t/op/warn.t
+++ b/t/op/warn.t
@@ -7,7 +7,7 @@ BEGIN {
require './test.pl';
}
-plan 18;
+plan 20;
my @warnings;
my $wa = []; my $ea = [];
@@ -107,4 +107,28 @@ $@ = $ea;
warn;
ok @warnings==1 && ref($warnings[0]) eq "ARRAY" && $warnings[0] == $ea;
+fresh_perl_like(
+ '
+ $a = "\xee\n";
+ print STDERR $a; warn $a;
+ utf8::upgrade($a);
+ print STDERR $a; warn $a;
+ ',
+ qr/^\xee(?:\r?\n\xee){3}/,
+ {},
+ 'warn emits logical characters, not internal bytes [perl #45549]'
+);
+
+fresh_perl_like(
+ '
+ $a = "\xee\n";
+ print STDERR $a; warn $a;
+ utf8::upgrade($a);
+ print STDERR $a; warn $a;
+ ',
+ qr/^\xc3\xae(?:\r?\n\xc3\xae){3}/,
+ { switches => ['-CE'] },
+ 'warn respects :utf8 layer'
+);
+
1;
diff --git a/util.c b/util.c
index 1809f707af..2ab14d71ed 100644
--- a/util.c
+++ b/util.c
@@ -1399,10 +1399,8 @@ Perl_write_to_stderr(pTHX_ SV* msv)
dSAVED_ERRNO;
#endif
PerlIO * const serr = Perl_error_log;
- STRLEN msglen;
- const char* message = SvPVx_const(msv, msglen);
- PERL_WRITE_MSG_TO_CONSOLE(serr, message, msglen);
+ do_print(msv, serr);
(void)PerlIO_flush(serr);
#ifdef USE_SFIO
RESTORE_ERRNO;