[monitoring-plugin-perl] Fix an incorrect hyphen removal due to a double ...

Ton Voon git at monitoring-plugins.org
Tue Feb 2 19:30:04 CET 2021


 Module: monitoring-plugin-perl
 Branch: fix_munged_hyphen
 Commit: 7fe1e44fb792626c17f373d785d9ee0e49eb1eb6
 Author: Ton Voon <ton.voon at opsview.com>
   Date: Tue Feb  2 18:21:22 2021 +0000
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugin-perl/commit/?id=7fe1e44

Fix an incorrect hyphen removal due to a double linefeed

---

 lib/Monitoring/Plugin/Functions.pm |  2 +-
 t/Monitoring-Plugin-Functions-01.t | 13 ++++++-------
 2 files changed, 7 insertions(+), 8 deletions(-)

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 )



More information about the Commits mailing list