[perl #82854] utf8, $SIG{__DIE__}, syntax errors and Carp
authorFather Chrysostomos <sprout@cpan.org>
Tue, 8 Feb 2011 00:49:38 +0000 (16:49 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 8 Feb 2011 00:53:37 +0000 (16:53 -0800)
commit018c7c82242b909397f06dbd208a750677dd822a
treeb9b6508a8218a9e06d13b8d20c72496e417835a6
parent76cc22ec8d16738e37cbdd3bb7205aed330bd0e7
[perl #82854] utf8, $SIG{__DIE__}, syntax errors and Carp

If a syntax error has occurred, module loading causes the ‘BEGIN not
safe after errors’ error.

As of perl 5.12.0 (commit 7d0994e05, actually), error messages men-
tioning variable names that originate from ‘use utf8’ scopes and are
passed to __DIE__ handlers correctly have the UTF8 flag turned on, so
that a variable named $ġ will actually cause the error message to con-
tain ‘$ġ’, rather than ‘$Ä¡’. (As a side effect, even if the variable
does not contain non-ASCII characters, the error message still gets
the UTF8 flag turned on.)

Carp was using a \d in a regular expression against the error message.

\d loads Unicode tables if the LHS has the UTF8 flag turned on.

This means that this snippet:

use utf8;
use strict;
use CGI::Carp 'fatalsToBrowser';
$c;

dies with ‘BEGIN not safe...’, because the error message that triggers
it is ‘Global symbol "$c" requires explicit package name’, it has the
UTF8 flag turned on, CGI::Carp passes it to Carp.pm, Carp tries to do
a /\d/ match against it and \d tries to load Unicode tables, dying
with ‘BEGIN not safe...‘.

This commit just changes the \d in Carp.pm to [0-9], since that is
what was intended anyway.
lib/Carp.pm
lib/Carp.t