From 7fe1e44fb792626c17f373d785d9ee0e49eb1eb6 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Tue, 2 Feb 2021 18:21:22 +0000 Subject: Fix an incorrect hyphen removal due to a double linefeed diff --git a/lib/Monitoring/Plugin/Functions.pm b/lib/Monitoring/Plugin/Functions.pm index 3eaf9e3..cc938e5 100644 --- a/lib/Monitoring/Plugin/Functions.pm +++ b/lib/Monitoring/Plugin/Functions.pm @@ -119,7 +119,7 @@ sub plugin_exit { # Setup output my $output = "$STATUS_TEXT{$code}"; if (defined $message && $message ne '') { - $output .= " - " unless $message =~ /^\s*\n/mxs; + $output .= " - " unless $message =~ /^\s*[\n\r]/; $output .= $message; } my $shortname = ($arg->{plugin} ? $arg->{plugin}->shortname : undef); diff --git a/t/Monitoring-Plugin-Functions-01.t b/t/Monitoring-Plugin-Functions-01.t index 3f1ab75..acce176 100644 --- a/t/Monitoring-Plugin-Functions-01.t +++ b/t/Monitoring-Plugin-Functions-01.t @@ -1,6 +1,6 @@ use strict; -use Test::More tests => 116; +use Test::More tests => 117; BEGIN { use_ok("Monitoring::Plugin::Functions", ":all"); } Monitoring::Plugin::Functions::_fake_exit(1); @@ -90,15 +90,14 @@ for (@ugly2) { # plugin_exit message with longoutput my @ugly3 = ( - [ "MSG\nLONGOUTPUT", " - MSG\nLONGOUTPUT" ], - [ "\nLONGOUTPUT", "\nLONGOUTPUT" ], - [ " \nLONGOUTPUT", " \nLONGOUTPUT" ], + [ "MSG\nLONGOUTPUT", "MONITORING-PLUGIN-FUNCTIONS-01 CRITICAL - MSG\nLONGOUTPUT\n" ], + [ "\nLONGOUTPUT", "MONITORING-PLUGIN-FUNCTIONS-01 CRITICAL\nLONGOUTPUT\n" ], + [ " \nLONGOUTPUT", "MONITORING-PLUGIN-FUNCTIONS-01 CRITICAL \nLONGOUTPUT\n" ], + [ "LONGOUTPUT\n\n blah.", "MONITORING-PLUGIN-FUNCTIONS-01 CRITICAL - LONGOUTPUT\n\n blah.\n" ], ); for (@ugly3) { $r = plugin_exit(CRITICAL, $_->[0]); - like($r->message, qr/CRITICAL$_->[1]$/, - sprintf('plugin_exit(CRITICAL, $msg) output matched "%s"', - "CRITICAL$_->[1]")); + is($r->message, $_->[1], "plugin_exit() output as expected"); } # Test plugin_die( $msg ) -- cgit v0.10-9-g596f