Commit 7fae35f1 authored by Shawn M Moore's avatar Shawn M Moore
Browse files

Check more thoroughly for Text::Template parse errors

    [issues.bestpractical.com #16346]
parent f7892ec1
......@@ -472,7 +472,7 @@ sub _ParseContentSimple {
SOURCE => $args{Content},
);
my ($ok) = $template->compile;
return ( undef, $self->loc('Template parsing error') ) if !$ok;
return ( undef, $self->loc('Template parsing error: [_1]', $Text::Template::ERROR) ) if !$ok;
# copied from Text::Template::fill_in and refactored to be simple variable
# interpolation
......@@ -673,7 +673,8 @@ sub CompileCheck {
TYPE => 'STRING',
SOURCE => $content,
);
$template->compile;
my ($ok) = $template->compile;
return ( undef, $self->loc('Template parsing error: [_1]', $Text::Template::ERROR) ) if !$ok;
# copied from Text::Template::fill_in and refactored to be compile checks
foreach my $fi_item (@{$template->{SOURCE}}) {
......
use strict;
use warnings;
use RT;
use RT::Test tests => 199;
use RT::Test tests => 231;
my $queue = RT::Queue->new(RT->SystemUser);
$queue->Load("General");
......@@ -148,6 +148,7 @@ TemplateTest(
TemplateTest(
Content => "\ntest { *!( }",
SyntaxError => 1,
PerlOutput => undef,
PerlWarnings => qr/syntax error/,
SimpleOutput => "test { *!( }",
......@@ -155,6 +156,7 @@ TemplateTest(
TemplateTest(
Content => "\ntest { \$rtname ",
SyntaxError => 1,
PerlOutput => undef,
SimpleOutput => undef,
);
......@@ -222,7 +224,19 @@ sub IndividualTemplateTest {
is($t->Content, $args{Content}, "$args{Type} content");
is($t->Type, $args{Type}, "template type");
my ($ok, $msg) = $t->Parse(
# this should never blow up!
my ($ok, $msg) = $t->CompileCheck;
# we don't need to syntax check simple templates since if you mess them up
# it's safe to just use the input directly as the template's output
if ($args{SyntaxError} && $args{Type} eq 'Perl') {
ok(!$ok, "got a syntax error");
}
else {
ok($ok, $msg);
}
($ok, $msg) = $t->Parse(
TicketObj => $ticket,
TransactionObj => $txn,
);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment