Skip to content

Reduce false positive by ending at an operator for issue #20 #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions lib/Perl/Critic/Policy/ValuesAndExpressions/PreventSQLInjection.pm
Original file line number Diff line number Diff line change
Expand Up @@ -372,27 +372,18 @@ sub detect_sql_injections
push( @$sql_injections, @{ analyze_string_injections( $self, $token ) || [] } );
}
# If it is a concatenation operator, continue to the next token.
elsif ( $token->isa('PPI::Token::Operator') && $token->content() eq '.' )
elsif ( $token->isa('PPI::Token::Operator') && grep { $token->content() eq $_ } qw{ . .= } )
{
# Skip to the next token.
}
# If it is a semicolon, we're at the end of the statement and we can finish
# the process.
elsif ( $token->isa('PPI::Token::Structure') && $token->content() eq ';' )
# If it is other operator, finish the process.
elsif ( $token->isa('PPI::Token::Operator') )
{
last;
}
# If we detect a ':' operator, we're at the end of the second argument in a
# ternary "... ? ... : ..." and we need to finish the process here as the
# third argument is not concatenated to the this string and will be
# analyzed separately.
elsif ( $token->isa('PPI::Token::Operator') && $token->content() eq ':' )
{
last;
}
# If it is a list-separating comma, this list element ends here and we can
# finish the process.
elsif ( $token->isa('PPI::Token::Operator') && $token->content() eq ',' )
# If it is a semicolon, we're at the end of the statement and we can finish
# the process.
elsif ( $token->isa('PPI::Token::Structure') && $token->content() eq ';' )
{
last;
}
Expand Down