Prechádzať zdrojové kódy

Merge pull request #349 from Troglodyne-Internet-Widgets/prohibit-regex-to-chomp

Take the newline off a syslog line with chomp, and hold the tree to it
George S. Baugh 1 mesiac pred
rodič
commit
02aa4a31c4
3 zmenil súbory, kde vykonal 5 pridanie a 4 odobranie
  1. 1 0
      .perlcriticrc
  2. 1 1
      lib/Trog/Log/Syslog.pm
  3. 3 3
      t/Trog-Log-Syslog.t

+ 1 - 0
.perlcriticrc

@@ -46,6 +46,7 @@ formats = #!/usr/bin/env perl
 [logicLAB::ProhibitShellDispatch]
 [logicLAB::ProhibitShellDispatch]
 [ProhibitPipeOpen]
 [ProhibitPipeOpen]
 [Performance::ProhibitRegexForSimpleSubstring]
 [Performance::ProhibitRegexForSimpleSubstring]
+[RegularExpressions::ProhibitRegexToChomp]
 # Extensions to perl -c
 # Extensions to perl -c
 [CompileTime]
 [CompileTime]
 # Good idea, but module doesn't install due to bad testsuite...we'll have to fork
 # Good idea, but module doesn't install due to bad testsuite...we'll have to fork

+ 1 - 1
lib/Trog/Log/Syslog.pm

@@ -73,7 +73,7 @@ sub log_message ( $self, %p ) {
 
 
     # Trog::Log ends every line with a newline, which a syslog message does
     # Trog::Log ends every line with a newline, which a syslog message does
     # not carry.
     # not carry.
-    my $message = $p{message} =~ s/\n+\z//r;
+    chomp( my $message = $p{message} );
 
 
     local $@;
     local $@;
     eval {
     eval {

+ 3 - 3
t/Trog-Log-Syslog.t

@@ -36,9 +36,9 @@ subtest 'a line arrives as the syslog of this machine reads it' => sub {
     my $got = received();
     my $got = received();
 
 
     # daemon is facility 3 and info is severity 6, so the priority is 3*8+6.
     # daemon is facility 3 and info is severity 6, so the priority is 3*8+6.
-    like( $got, qr/^<30>/,                                                                                            'as daemon.info' );
-    like( $got, qr/\btcms\[$$\]: /,                                                                                   'tagged with the program name and the pid' );
-    like( $got, qr/: 2026-09-29T12:00:00Z \[INFO\]: RequestId x From 192\.0\.2\.1 \|nobody\| Failed login for user$/, 'with the line that the file gets, and no newline' );
+    like( $got, qr/^<30>/,                                                                                             'as daemon.info' );
+    like( $got, qr/\btcms\[$$\]: /,                                                                                    'tagged with the program name and the pid' );
+    like( $got, qr/: 2026-09-29T12:00:00Z \[INFO\]: RequestId x From 192\.0\.2\.1 \|nobody\| Failed login for user\z/, 'with the line that the file gets, and no newline' );
 };
 };
 
 
 subtest 'each level keeps its severity' => sub {
 subtest 'each level keeps its severity' => sub {