Commit a275a7fa authored by Alex Vandiver's avatar Alex Vandiver
Browse files

Always log bytes, not characters

Ensure that we always send UTF-8 encoded bytes to loggers, and not wide
characters.  This is correctly done via an explicit call to
Encode::encode, and not via checks of utf8::is_utf8 (which may be false
for character strings with codepoints > 127 but < 256), and not via
_utf8_off (which would fail similarly for such characters).
parent 15dde68b
......@@ -263,6 +263,9 @@ sub InitLogging {
$frame++ while caller($frame) && caller($frame) =~ /^Log::/;
my ($package, $filename, $line) = caller($frame);
# Encode to bytes, so we don't send wide characters
$p{message} = Encode::encode("UTF-8", $p{message});
$p{'message'} =~ s/(?:\r*\n)+$//;
return "[$$] [". gmtime(time) ."] [". $p{'level'} ."]: "
. $p{'message'} ." ($filename:$line)\n";
......@@ -278,8 +281,8 @@ sub InitLogging {
$frame++ while caller($frame) && caller($frame) =~ /^Log::/;
my ($package, $filename, $line) = caller($frame);
# syswrite() cannot take utf8; turn it off here.
Encode::_utf8_off($p{message});
# Encode to bytes, so we don't send wide characters
$p{message} = Encode::encode("UTF-8", $p{message});
$p{message} =~ s/(?:\r*\n)+$//;
if ($p{level} eq 'debug') {
......
......@@ -535,15 +535,11 @@ sub _ParseMultilineTemplate {
my %args = (@_);
my $template_id;
require Encode;
require utf8;
my ( $queue, $requestor );
$RT::Logger->debug("Line: ===");
foreach my $line ( split( /\n/, $args{'Content'} ) ) {
$line =~ s/\r$//;
$RT::Logger->debug( "Line: " . utf8::is_utf8($line)
? Encode::encode_utf8($line)
: $line );
$RT::Logger->debug( "Line: $line" );
if ( $line =~ /^===/ ) {
if ( $template_id && !$queue && $args{'Queue'} ) {
$self->{'templates'}->{$template_id}
......
......@@ -75,11 +75,7 @@ $SuppressHeader => 0,
my $error = $Why;
$error .= " ($Details)" if defined $Details && length $Details;
# TODO: Log::Dispatch isn't UTF-8 safe. Autrijus needs to talk to dave rolsky about getting this fixed
use Encode ();
Encode::_utf8_off($error);
$RT::Logger->error($error);
$RT::Logger->error( $error );
if ( $session{'REST'} ) {
$r->content_type('text/plain; charset=utf-8');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment