Skip to content

Commit 49b2c9b

Browse files
(GH-14) Fix inconsistency in PPI::Token::HereDoc->heredoc().
Due to a bug in PPI::Token::Heredoc, $token->heredoc() does not include the terminator line when the terminator is a simple bareword, but it includes the terminator line in the other cases (single/double quoted , commands, escaped). I wrote a patch to resolve this in PPI (see Perl-Critic/PPI#71), but in the meantime this addresses the inconsistency.
1 parent 92f56a4 commit 49b2c9b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,17 @@ sub get_token_content
413413
if ( $token->isa('PPI::Token::HereDoc') )
414414
{
415415
my @heredoc = $token->heredoc();
416+
417+
# Due to a bug in PPI::Token::Heredoc, $token->heredoc():
418+
# - does not include the terminator line when the terminator is a simple
419+
# bareword;
420+
# - includes the terminator line in the other cases (single/double
421+
# quoted , commands, escaped).
422+
# See https://github.com/adamkennedy/PPI/pull/71, but in the meantime this
423+
# addresses the inconsistency:
424+
pop( @heredoc )
425+
if $token->content() =~ /^\<\<['"`\\]/;
426+
416427
$content = join( '', @heredoc );
417428
}
418429
elsif ( $token->isa('PPI::Token::Quote' ) )

0 commit comments

Comments
 (0)