Permalink
Browse files

Restrict `blocktrans` content to only strings and plain variables. #88

This matches Django behaviour.
  • Loading branch information...
1 parent c863220 commit 65397295163d3bdf927ba96185a8bd185454e2fc @seriyps seriyps committed Feb 12, 2014
Showing with 9 additions and 2 deletions.
  1. +7 −2 src/erlydtl_parser.yrl
  2. +2 −0 tests/src/erlydtl_unittests.erl
View
@@ -113,6 +113,7 @@ Nonterminals
SSITag
BlockTransBlock
+ BlockTransContent
TransTag
TemplatetagTag
@@ -367,8 +368,12 @@ SpacelessBlock -> open_tag spaceless_keyword close_tag Elements open_tag endspac
SSITag -> open_tag ssi_keyword Value close_tag : {ssi, '$3'}.
SSITag -> open_tag ssi_keyword string_literal parsed_keyword close_tag : {ssi_parsed, '$3'}.
-BlockTransBlock -> open_tag blocktrans_keyword close_tag Elements open_tag endblocktrans_keyword close_tag : {blocktrans, [], '$4'}.
-BlockTransBlock -> open_tag blocktrans_keyword with_keyword Args close_tag Elements open_tag endblocktrans_keyword close_tag : {blocktrans, '$4', '$6'}.
+BlockTransBlock -> open_tag blocktrans_keyword close_tag BlockTransContent open_tag endblocktrans_keyword close_tag : {blocktrans, [], '$4'}.
+BlockTransBlock -> open_tag blocktrans_keyword with_keyword Args close_tag BlockTransContent open_tag endblocktrans_keyword close_tag : {blocktrans, '$4', '$6'}.
+BlockTransContent -> '$empty' : [].
+BlockTransContent -> BlockTransContent open_var identifier close_var : '$1' ++ [{variable, '$3'}].
+BlockTransContent -> BlockTransContent string : '$1' ++ ['$2'].
+%% TODO: {% plural %}
TemplatetagTag -> open_tag templatetag_keyword Templatetag close_tag : {templatetag, '$3'}.
@@ -1191,6 +1191,8 @@ tests() ->
[{blocktrans_locales, ["de"]}, {blocktrans_fun, fun("Hello, {{ name }}", "de") -> <<"Guten tag, {{ name }}">> end}], <<"Guten tag, Mr. President">>},
{"blocktrans with args",
<<"{% blocktrans with var1=foo %}{{ var1 }}{% endblocktrans %}">>, [{foo, "Hello"}], <<"Hello">>}
+ %% {"blocktrans complex not allowed",
+ %% <<"{% blocktrans %}Hello{%if user%}, {{ user.name }}{%endif%}!{% endblocktrans %}">>, [], assert-raise-syntax-error}
]},
{"verbatim", [
{"Plain verbatim",

0 comments on commit 6539729

Please sign in to comment.