Fix unstable use of $1 in Qpsmtpd::warn_level()

This commit is contained in:
Jared Johnson 2014-12-17 16:11:12 -06:00
parent b42b3c92a1
commit 4d59ce8406
2 changed files with 8 additions and 2 deletions

View File

@ -103,8 +103,8 @@ sub warn_level {
my @levels = ( keys %Qpsmtpd::Constants::log_levels,
qw[ LOGWARNING LOGCRITICAL LOGEMERGENCY ] );
my $levels = join '|', map { s/^LOG//; $_ } @levels;
$warnings[0] =~ s/^($levels):\s*//;
my $prefix = $1;
my $prefix;
$prefix = $1 if $warnings[0] =~ s/^($levels):\s*//;
$prefix = 'WARN' if ! $prefix;
$prefix = 'WARN' if $prefix eq 'WARNING';
$prefix = 'CRIT' if $prefix eq 'CRITICAL';

View File

@ -355,6 +355,12 @@ sub __warn_level {
is( log_level($level), 'LOGWARN', 'Correct log level with no prefix' );
is( $msg, 'qwerty', 'Correct message with no prefix' );
my $s = 'abc123';
$s =~ /(abc)/;
( $level, $msg ) = $qp->warn_level('dvorak');
is( log_level($level), 'LOGWARN', 'Correct level after $1 assignment' );
is( $msg, 'dvorak', 'Correct message with no prefix after $1 assignment' );
( $level, $msg ) = $qp->warn_level('NOTICE: asdf');
is( log_level($level), 'LOGNOTICE', 'Correct level with NOTICE prefix' );
is( $msg, 'asdf', 'Correct message with NOTICE prefix' );