[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.