Skip to content

Commit

Permalink
Added warnings_as_string
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Feb 10, 2025
1 parent 09669ef commit a5b035f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Revision history for CGI-Info
0.91
Added t/waf.t to test the Web Application Firewall
params: instead of cleaning up XSS, now sets them to 403 and doesn't pass the values back
Added warnings_as_string

0.90 Tue Feb 4 08:57:49 EST 2025
Ensure status is set before calling _warn so it's not lost (some 403s were being lost)
Expand Down
20 changes: 16 additions & 4 deletions lib/CGI/Info.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ sub _sanitise_input($);
CGI::Info - Information about the CGI environment
=head1 DESCRIPTION
CGI::Info gets information about the system that a CGI script is running on.
=head1 VERSION
Version 0.90
Expand Down Expand Up @@ -1787,6 +1783,22 @@ sub warnings
return $self->{'warnings'};
}

=head2 warnings_as_string
Returns the warnings that the object has generated as a string.
=cut

sub warnings_as_string
{
my $self = shift;

if(scalar($self->{'warnings'})) {
my @warnings = map { $_->{'warning'} } @{$self->{'warnings'}};
return join('; ', @warnings);
}
}

=head2 set_logger
Sets the class, code reference, or file that will be used for logging.
Expand Down
6 changes: 4 additions & 2 deletions t/params.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use strict;
use warnings;
use Test::Most tests => 197;
use Test::Most tests => 199;
use File::Spec;
use lib 't/lib';
use MyLogger;
Expand All @@ -18,6 +18,7 @@ PARAMS: {

my $i = new_ok('CGI::Info');
ok(!defined($i->warnings()));
ok(!defined($i->warnings_as_string()));
my %p = %{$i->params()};
ok($p{foo} eq 'bar');
ok(!defined($p{fred}));
Expand Down Expand Up @@ -460,9 +461,10 @@ EOF
diag(Data::Dumper->new([$i->warnings()])->Dump()) if($ENV{'TEST_VERBOSE'});
like(
$i->warnings()->[0]->{'warning'},
qr/Blocked directory traversal attack for 'file'/,
qr/^Blocked directory traversal attack for 'file'/,
'Warning generated for disallowed parameter'
);
like($i->warnings_as_string(), qr/^Blocked directory traversal attack/, 'warnings_as_string works');

@ARGV= ('file=/etc/passwd%00');
$i = new_ok('CGI::Info');
Expand Down

0 comments on commit a5b035f

Please sign in to comment.