[Rt-commit] rt branch, 4.0-trunk, updated. rt-3.9.7-1134-g7fae35f

Shawn Moore sartak at bestpractical.com
Wed Dec 29 15:26:14 EST 2010


The branch, 4.0-trunk has been updated
       via  7fae35f16881c000390c589f84be569d5c55ceda (commit)
      from  f7892ec19eefc48a071465e480be8dcd4444637c (commit)

Summary of changes:
 lib/RT/Template.pm      |    5 +++--
 t/api/template-simple.t |   18 ++++++++++++++++--
 2 files changed, 19 insertions(+), 4 deletions(-)

- Log -----------------------------------------------------------------
commit 7fae35f16881c000390c589f84be569d5c55ceda
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Dec 29 15:24:47 2010 -0500

    Check more thoroughly for Text::Template parse errors
    
        [issues.bestpractical.com #16346]

diff --git a/lib/RT/Template.pm b/lib/RT/Template.pm
index cb8ef23..0e2e359 100644
--- a/lib/RT/Template.pm
+++ b/lib/RT/Template.pm
@@ -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}}) {
diff --git a/t/api/template-simple.t b/t/api/template-simple.t
index f945580..21f8d47 100644
--- a/t/api/template-simple.t
+++ b/t/api/template-simple.t
@@ -1,7 +1,7 @@
 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,
     );

-----------------------------------------------------------------------


More information about the Rt-commit mailing list