Skip to content

Commit

Permalink
Fix for erlydtl crash with recursive block definitions. Added extra t…
Browse files Browse the repository at this point in the history
…est.
  • Loading branch information
mworrell committed Sep 10, 2010
1 parent 9df4334 commit 501697e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/erlydtl/erlydtl_compiler.erl
Expand Up @@ -364,9 +364,16 @@ body_ast(DjangoParseTree, Context, TreeWalker) ->
error ->
{CurrentFile, Contents}
end,
body_ast(Block,
Context1#dtl_context{block_trail=[{Name,BlockFile}|Context1#dtl_context.block_trail]},
TreeWalkerAcc);
% Check if we have a recursive definition
case lists:member({Name,BlockFile}, Context#dtl_context.block_trail) of
true ->
?ERROR("body_ast: recursive block ~p (~p)", [Name, BlockFile]),
throw({error, "Recursive block definition of '" ++ Name ++ "' (" ++ BlockFile ++ ")"});
false ->
body_ast(Block,
Context1#dtl_context{block_trail=[{Name,BlockFile}|Context1#dtl_context.block_trail]},
TreeWalkerAcc)
end;
('inherit', TreeWalkerAcc) ->
inherit_ast(Context, TreeWalkerAcc);
({'comment', _Contents}, TreeWalkerAcc) ->
Expand Down
7 changes: 7 additions & 0 deletions src/tests/erlydtl/docroot/block_recurse_error
@@ -0,0 +1,7 @@
{% extends "base" %}

{% block content %}
foo
{% block content %}oof{% endblock %}
bar
{% endblock %}
4 changes: 4 additions & 0 deletions src/tests/erlydtl_functional_tests.erl
Expand Up @@ -51,6 +51,7 @@ test_list() ->
"var", "cycle",
"custom_tag",
% "custom_tag_error",
"block_recurse_error",
"custom_call",
"with_multiple"
].
Expand Down Expand Up @@ -86,6 +87,9 @@ setup_compile("var_preset") ->
setup_compile("custom_tag_error") ->
CompileVars = [],
{error, CompileVars};
setup_compile("block_recurse_error") ->
CompileVars = [],
{error, CompileVars};
setup_compile(_) ->
{ok, []}.

Expand Down

0 comments on commit 501697e

Please sign in to comment.