Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

This matches Django behaviour.
  • Loading branch information...
commit 65397295163d3bdf927ba96185a8bd185454e2fc 1 parent c863220
@seriyps seriyps authored
Showing with 9 additions and 2 deletions.
  1. +7 −2 src/erlydtl_parser.yrl
  2. +2 −0  tests/src/erlydtl_unittests.erl
View
9 src/erlydtl_parser.yrl
@@ -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'}.
View
2  tests/src/erlydtl_unittests.erl
@@ -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",
Please sign in to comment.
Something went wrong with that request. Please try again.