Skip to content

Commit 1dc0279

Browse files
committed
Fixed - was not working for variables in last line of heredoc.
It seems that heredoc() method excludes terminator line, so no need to pop() https://metacpan.org/pod/PPI::Token::HereDoc#heredoc added test for the bug, also added additional test to extract_variables (just to make sure our regexp deals with newlines right)
1 parent ebd3987 commit 1dc0279

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lib/Perl/Critic/Policy/ValuesAndExpressions/PreventSQLInjection.pm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ sub get_token_content
413413
if ( $token->isa('PPI::Token::HereDoc') )
414414
{
415415
my @heredoc = $token->heredoc();
416-
pop( @heredoc ); # Remove the heredoc termination tag.
417416
$content = join( '', @heredoc );
418417
}
419418
elsif ( $token->isa('PPI::Token::Quote' ) )

t/10-extract_variables.t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ my $tests =
1515
string => 'A test $variable string',
1616
expected => [ '$variable' ],
1717
},
18+
{
19+
string => "A test string\n with \$variable",
20+
expected => [ '$variable' ],
21+
},
1822
{
1923
string => 'A test $variable $variable string',
2024
expected => [ '$variable' ],

t/ValuesAndExpressions/PreventSQLInjection.run

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ my $heredoc = <<__HERE__
104104
FROM $table
105105
__HERE__
106106

107+
## name Heredoc with variable in last line
108+
## failures 1
109+
## cut
110+
111+
my $heredoc = <<__HERE__
112+
SELECT
113+
FROM $table
114+
__HERE__
115+
107116
## name Double-quoted heredoc with multiple variables.
108117
## failures 1
109118
## cut

0 commit comments

Comments
 (0)