summaryrefslogtreecommitdiff
path: root/django/template/__init__.py
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-04-11 12:03:52 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-04-11 12:03:52 +0000
commitb1a5db37e6631ab4a964d7f8d52dfe593f9e6c4b (patch)
tree3ce24d81abffe8ec5ca053f22f7849566cffe866 /django/template/__init__.py
parentd18f75af447bc18b062564ab163943c16d79effc (diff)
Fixed #10369 -- Fixed auto-escaping inside "tran" and "blocktrans" tags.
Patch from Andrew Badr. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10519 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/template/__init__.py')
-rw-r--r--django/template/__init__.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/django/template/__init__.py b/django/template/__init__.py
index 95aa36af21..5493e5bbb7 100644
--- a/django/template/__init__.py
+++ b/django/template/__init__.py
@@ -801,6 +801,18 @@ class TextNode(Node):
def render(self, context):
return self.s
+
+def _render_value_in_context(value, context):
+ """
+ Converts any value to a string to become part of a rendered template. This
+ means escaping, if required, and conversion to a unicode object. If value
+ is a string, it is expected to have already been translated.
+ """
+ value = force_unicode(value)
+ if (context.autoescape and not isinstance(value, SafeData)) or isinstance(value, EscapeData):
+ return escape(value)
+ else:
+ return value
class VariableNode(Node):
def __init__(self, filter_expression):
@@ -811,15 +823,12 @@ class VariableNode(Node):
def render(self, context):
try:
- output = force_unicode(self.filter_expression.resolve(context))
+ output = self.filter_expression.resolve(context)
except UnicodeDecodeError:
# Unicode conversion can fail sometimes for reasons out of our
# control (e.g. exception rendering). In that case, we fail quietly.
return ''
- if (context.autoescape and not isinstance(output, SafeData)) or isinstance(output, EscapeData):
- return force_unicode(escape(output))
- else:
- return force_unicode(output)
+ return _render_value_in_context(output, context)
def generic_tag_compiler(params, defaults, name, node_class, parser, token):
"Returns a template.Node subclass."