Author: mtredinnick
Date: 2007-11-14 15:07:27 -0600 (Wed, 14 Nov 2007)
New Revision: 6673
Modified:
django/trunk/django/template/loader_tags.py
django/trunk/docs/templates.txt
django/trunk/tests/regressiontests/templates/tests.py
Log:
Content coming via {{ block.super }} is always going to be correctly escaped
already. We mark it as safe so that template authors don't need to.
Modified: django/trunk/django/template/loader_tags.py
===================================================================
--- django/trunk/django/template/loader_tags.py 2007-11-14 19:13:37 UTC (rev
6672)
+++ django/trunk/django/template/loader_tags.py 2007-11-14 21:07:27 UTC (rev
6673)
@@ -2,6 +2,7 @@
from django.template import Library, Node
from django.template.loader import get_template, get_template_from_string,
find_template_source
from django.conf import settings
+from django.utils.safestring import mark_safe
register = Library()
@@ -26,7 +27,7 @@
def super(self):
if self.parent:
- return self.parent.render(self.context)
+ return mark_safe(self.parent.render(self.context))
return ''
def add_parent(self, nodelist):
Modified: django/trunk/docs/templates.txt
===================================================================
--- django/trunk/docs/templates.txt 2007-11-14 19:13:37 UTC (rev 6672)
+++ django/trunk/docs/templates.txt 2007-11-14 21:07:27 UTC (rev 6673)
@@ -280,7 +280,9 @@
* If you need to get the content of the block from the parent template,
the ``{{ block.super }}`` variable will do the trick. This is useful
if you want to add to the contents of a parent block instead of
- completely overriding it.
+ completely overriding it. Data inserted using ``{{ block.super }}`` will
+ not be automatically escaped (see the `next section`_), since it was
+ already escaped, if necessary, in the parent template.
* For extra readability, you can optionally give a *name* to your
``{% endblock %}`` tag. For example::
@@ -299,6 +301,8 @@
two similarly-named ``{% block %}`` tags in a template, that template's parent
wouldn't know which one of the blocks' content to use.
+.. _next section: #automatic-html-escaping
+
Automatic HTML escaping
=======================
Modified: django/trunk/tests/regressiontests/templates/tests.py
===================================================================
--- django/trunk/tests/regressiontests/templates/tests.py 2007-11-14
19:13:37 UTC (rev 6672)
+++ django/trunk/tests/regressiontests/templates/tests.py 2007-11-14
21:07:27 UTC (rev 6673)
@@ -617,7 +617,7 @@
### INHERITANCE
###########################################################
# Standard template with no inheritance
- 'inheritance01': ("1{% block first %}_{% endblock %}3{% block
second %}_{% endblock %}", {}, '1_3_'),
+ 'inheritance01': ("1{% block first %}&{% endblock %}3{% block
second %}_{% endblock %}", {}, '1&3_'),
# Standard two-level inheritance
'inheritance02': ("{% extends 'inheritance01' %}{% block first
%}2{% endblock %}{% block second %}4{% endblock %}", {}, '1234'),
@@ -626,7 +626,7 @@
'inheritance03': ("{% extends 'inheritance02' %}", {}, '1234'),
# Two-level with no redefinitions on second level
- 'inheritance04': ("{% extends 'inheritance01' %}", {}, '1_3_'),
+ 'inheritance04': ("{% extends 'inheritance01' %}", {}, '1&3_'),
# Two-level with double quotes instead of single quotes
'inheritance05': ('{% extends "inheritance02" %}', {}, '1234'),
@@ -635,16 +635,16 @@
'inheritance06': ("{% extends foo %}", {'foo': 'inheritance02'},
'1234'),
# Two-level with one block defined, one block not defined
- 'inheritance07': ("{% extends 'inheritance01' %}{% block second
%}5{% endblock %}", {}, '1_35'),
+ 'inheritance07': ("{% extends 'inheritance01' %}{% block second
%}5{% endblock %}", {}, '1&35'),
# Three-level with one block defined on this level, two blocks
defined next level
'inheritance08': ("{% extends 'inheritance02' %}{% block second
%}5{% endblock %}", {}, '1235'),
# Three-level with second and third levels blank
- 'inheritance09': ("{% extends 'inheritance04' %}", {}, '1_3_'),
+ 'inheritance09': ("{% extends 'inheritance04' %}", {}, '1&3_'),
# Three-level with space NOT in a block -- should be ignored
- 'inheritance10': ("{% extends 'inheritance04' %} ", {},
'1_3_'),
+ 'inheritance10': ("{% extends 'inheritance04' %} ", {},
'1&3_'),
# Three-level with both blocks defined on this level, but none on
second level
'inheritance11': ("{% extends 'inheritance04' %}{% block first
%}2{% endblock %}{% block second %}4{% endblock %}", {}, '1234'),
@@ -656,7 +656,7 @@
'inheritance13': ("{% extends 'inheritance02' %}{% block first
%}a{% endblock %}{% block second %}b{% endblock %}", {}, '1a3b'),
# A block defined only in a child template shouldn't be displayed
- 'inheritance14': ("{% extends 'inheritance01' %}{% block newblock
%}NO DISPLAY{% endblock %}", {}, '1_3_'),
+ 'inheritance14': ("{% extends 'inheritance01' %}{% block newblock
%}NO DISPLAY{% endblock %}", {}, '1&3_'),
# A block within another block
'inheritance15': ("{% extends 'inheritance01' %}{% block first
%}2{% block inner %}inner{% endblock %}{% endblock %}", {}, '12inner3_'),
@@ -674,16 +674,16 @@
'inheritance19': ("{% extends 'inheritance01' %}{% block first
%}{% load testtags %}{% echo 400 %}5678{% endblock %}", {}, '140056783_'),
# Two-level inheritance with {{ block.super }}
- 'inheritance20': ("{% extends 'inheritance01' %}{% block first
%}{{ block.super }}a{% endblock %}", {}, '1_a3_'),
+ 'inheritance20': ("{% extends 'inheritance01' %}{% block first
%}{{ block.super }}a{% endblock %}", {}, '1&a3_'),
# Three-level inheritance with {{ block.super }} from parent
'inheritance21': ("{% extends 'inheritance02' %}{% block first
%}{{ block.super }}a{% endblock %}", {}, '12a34'),
# Three-level inheritance with {{ block.super }} from grandparent
- 'inheritance22': ("{% extends 'inheritance04' %}{% block first
%}{{ block.super }}a{% endblock %}", {}, '1_a3_'),
+ 'inheritance22': ("{% extends 'inheritance04' %}{% block first
%}{{ block.super }}a{% endblock %}", {}, '1&a3_'),
# Three-level inheritance with {{ block.super }} from parent and
grandparent
- 'inheritance23': ("{% extends 'inheritance20' %}{% block first
%}{{ block.super }}b{% endblock %}", {}, '1_ab3_'),
+ 'inheritance23': ("{% extends 'inheritance20' %}{% block first
%}{{ block.super }}b{% endblock %}", {}, '1&ab3_'),
# Inheritance from local context without use of template loader
'inheritance24': ("{% extends context_template %}{% block first
%}2{% endblock %}{% block second %}4{% endblock %}", {'context_template':
template.Template("1{% block first %}_{% endblock %}3{% block second %}_{%
endblock %}")}, '1234'),
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---