avoid deep recursion
when using a tt template for exceptions, and there is an exception in the template, don't go into infinite recursion.
This commit is contained in:
@@ -2,6 +2,7 @@ package Mojolicious::Plugin::TtRenderer::Engine;
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
use v5.10;
|
||||
|
||||
use base 'Mojo::Base';
|
||||
|
||||
@@ -30,7 +31,7 @@ sub _init {
|
||||
my $dir;
|
||||
my $app = delete $args{mojo} || delete $args{app};
|
||||
if($dir=$args{cache_dir}) {
|
||||
|
||||
|
||||
if($app && substr($dir,0,1) ne '/') {
|
||||
$dir=$app->home->rel_dir('tmp/ctpl');
|
||||
}
|
||||
@@ -88,11 +89,19 @@ sub _render {
|
||||
# Error
|
||||
unless ($ok) {
|
||||
|
||||
state $rendering_exception;
|
||||
|
||||
my $e = Mojo::Exception->new($self->tt->error.'');
|
||||
$$output = '';
|
||||
$c->app->log->error(qq/Template error in "$t": $e/);
|
||||
$c->render_exception($e);
|
||||
$self->tt->error('');
|
||||
|
||||
unless($rendering_exception)
|
||||
{
|
||||
$rendering_exception = 1;
|
||||
$c->render_exception($e);
|
||||
$rendering_exception = 0;
|
||||
$self->tt->error('');
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
55
t/deep_recursion.t
Normal file
55
t/deep_recursion.t
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
#BEGIN { $ENV{MOJO_MODE}='testing'; };
|
||||
|
||||
use utf8;
|
||||
|
||||
use Test::More tests => 3;
|
||||
|
||||
use Mojolicious::Lite;
|
||||
use Test::Mojo;
|
||||
|
||||
# Silence
|
||||
app->log->level('fatal');
|
||||
|
||||
plugin 'tt_renderer';
|
||||
|
||||
get '/exception' => sub { die };
|
||||
|
||||
#say app->mode;
|
||||
#app->start;
|
||||
#exit;
|
||||
|
||||
my $t = Test::Mojo->new;
|
||||
|
||||
$t->app->renderer->default_handler('tt');
|
||||
|
||||
my $deep_recursion = 0;
|
||||
|
||||
do {
|
||||
local $SIG{__WARN__} = sub {
|
||||
my $warning = shift;
|
||||
if($warning =~ /Deep recursion/) {
|
||||
$deep_recursion = 1;
|
||||
die $warning;
|
||||
}
|
||||
};
|
||||
$t->get_ok('/exception')
|
||||
->status_is(500);
|
||||
};
|
||||
|
||||
ok !$deep_recursion, 'no deep recursion';
|
||||
|
||||
__DATA__
|
||||
|
||||
@@ exception.development.html.tt
|
||||
[% 1 + % %]
|
||||
|
||||
@@ exception.html.tt
|
||||
[% 1 + % %]
|
||||
|
||||
@@ exception.testing.html.tt
|
||||
[% 1 + % %]
|
||||
Reference in New Issue
Block a user