diff --git a/Build.PL b/Build.PL index 0be71c8..e2738c7 100644 --- a/Build.PL +++ b/Build.PL @@ -44,6 +44,7 @@ my $builder = $class->new( 'Test::Deep' => 0, 'Test::FailWarnings' => 0, 'Test::More' => 0, + 'Test::Perl::Critic' => 0, 'Test::Perl::Critic::Policy' => 0, }, requires => diff --git a/lib/Perl/Critic/Policy/ValuesAndExpressions/PreventSQLInjection.pm b/lib/Perl/Critic/Policy/ValuesAndExpressions/PreventSQLInjection.pm index 0199ed0..24c71da 100644 --- a/lib/Perl/Critic/Policy/ValuesAndExpressions/PreventSQLInjection.pm +++ b/lib/Perl/Critic/Policy/ValuesAndExpressions/PreventSQLInjection.pm @@ -305,6 +305,20 @@ sub applies_to ); } +=head2 prepare_to_scan_document() + +Sets up policy ($self) for each new document before scanning. + + my $bool = $policy->prepare_to_scan_document(); + +=cut + +sub prepare_to_scan_document { + my ( $self, $doc ) = @_; + delete $self->{'_sqlsafe'}; + return $TRUE; +} + =head2 violates() diff --git a/t/45-multi-docs.t b/t/45-multi-docs.t new file mode 100644 index 0000000..ff22a30 --- /dev/null +++ b/t/45-multi-docs.t @@ -0,0 +1,17 @@ +#!perl + +use strict; +use warnings; + +use Test::FailWarnings -allow_deps => 1; +use Test::More tests => 2; +use Test::Perl::Critic; +use File::Spec; + +Test::Perl::Critic->import('-single-policy' => 'ValuesAndExpressions::PreventSQLInjection'); + +my $testfile1 = File::Spec->catfile( 't', 'files', 'test10.pl' ); +my $testfile2 = File::Spec->catfile( 't', 'files', 'test11.pl' ); + +all_critic_ok($testfile1, $testfile2 ); + diff --git a/t/files/test10.pl b/t/files/test10.pl new file mode 100755 index 0000000..869c162 --- /dev/null +++ b/t/files/test10.pl @@ -0,0 +1,8 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +my $str = "just a placeholder"; + +1; diff --git a/t/files/test11.pl b/t/files/test11.pl new file mode 100755 index 0000000..046a9cf --- /dev/null +++ b/t/files/test11.pl @@ -0,0 +1,8 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +my $username = "user1"; +my $sql = "select * from users WHERE user = $username"; ## SQL safe($username) +