From 1ea44a3abd4e58777247a095afd03dd01efdef55 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 21 Mar 2014 13:17:10 -0400 Subject: Switched {% cycle %} and {% firstof %} tags to auto-escape their variables per deprecation timeline. refs #17906. --- docs/ref/templates/builtins.txt | 58 ++++++++--------------------------------- 1 file changed, 11 insertions(+), 47 deletions(-) (limited to 'docs/ref') diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt index 4f8102c003..a73ba87d75 100644 --- a/docs/ref/templates/builtins.txt +++ b/docs/ref/templates/builtins.txt @@ -102,13 +102,11 @@ this:: {% endfor %} -Note that the variables included in the cycle will not be escaped. Any HTML or -Javascript code contained in the printed variable will be rendered as-is, which -could potentially lead to security issues. So either make sure that you trust -their values or use explicit escaping like this:: +Variables included in the cycle will be escaped. You can disable auto-escaping +with:: {% for o in some_list %} - + - ... - - {% endfor %} .. templatetag:: debug @@ -268,10 +251,8 @@ Sample usage:: firstof ^^^^^^^ -Outputs the first argument variable that is not False. This tag does *not* -auto-escape variable values. - -Outputs nothing if all the passed variables are False. +Outputs the first argument variable that is not ``False``. Outputs nothing if +all the passed variables are ``False``. Sample usage:: @@ -292,32 +273,15 @@ passed variables are False:: {% firstof var1 var2 var3 "fallback value" %} -Note that currently the variables included in the firstof tag will not be -escaped. Any HTML or Javascript code contained in the printed variable will be -rendered as-is, which could potentially lead to security issues. If you need -to escape the variables in the firstof tag, you must do so explicitly:: +This tag auto-escapes variable values. You can disable auto-escaping with:: - {% filter force_escape %} - {% firstof var1 var2 var3 "fallback value" %} - {% endfilter %} - -.. versionchanged:: 1.6 - - To improve safety, future versions of ``firstof`` will automatically escape - their output. You're encouraged to activate this behavior by loading - ``firstof`` from the ``future`` template library:: - - {% load firstof from future %} - - When using the ``future`` version, you can disable auto-escaping with:: - - {% autoescape off %} - {% firstof var1 var2 var3 "fallback value" %} - {% endautoescape %} + {% autoescape off %} + {% firstof var1 var2 var3 "fallback value" %} + {% endautoescape %} - Or if only some variables should be escaped, you can use:: +Or if only some variables should be escaped, you can use:: - {% firstof var1 var2|safe var3 "fallback value"|safe %} + {% firstof var1 var2|safe var3 "fallback value"|safe %} .. templatetag:: for -- cgit v1.3