Author: julien
Date: 2011-08-25 16:02:15 -0700 (Thu, 25 Aug 2011)
New Revision: 16687
Added:
django/trunk/tests/regressiontests/templates/templates/ssi include with
spaces.html
Modified:
django/trunk/django/templatetags/future.py
django/trunk/tests/regressiontests/templates/tests.py
Log:
Fixed #16677 -- Fixed the future version of the ssi template tag to work with
template file names that contain spaces. Note that this fix cannot be applied
to the currently deprecated version of the ssi tag since it requires an
unquoted literal as parameter. Many thanks to Aymeric Augustin for the report
and patch.
Modified: django/trunk/django/templatetags/future.py
===================================================================
--- django/trunk/django/templatetags/future.py 2011-08-25 09:23:49 UTC (rev
16686)
+++ django/trunk/django/templatetags/future.py 2011-08-25 23:02:15 UTC (rev
16687)
@@ -19,7 +19,7 @@
{% ssi "/home/html/ljworld.com/includes/right_generic.html" parsed %}
"""
- bits = token.contents.split()
+ bits = token.split_contents()
parsed = False
if len(bits) not in (2, 3):
raise TemplateSyntaxError("'ssi' tag takes one argument: the path to"
Added: django/trunk/tests/regressiontests/templates/templates/ssi include with
spaces.html
===================================================================
--- django/trunk/tests/regressiontests/templates/templates/ssi include with
spaces.html (rev 0)
+++ django/trunk/tests/regressiontests/templates/templates/ssi include with
spaces.html 2011-08-25 23:02:15 UTC (rev 16687)
@@ -0,0 +1 @@
+This is for testing an ssi include with spaces in its name. {{ test }}
Modified: django/trunk/tests/regressiontests/templates/tests.py
===================================================================
--- django/trunk/tests/regressiontests/templates/tests.py 2011-08-25
09:23:49 UTC (rev 16686)
+++ django/trunk/tests/regressiontests/templates/tests.py 2011-08-25
23:02:15 UTC (rev 16687)
@@ -508,7 +508,8 @@
def get_template_tests(self):
# SYNTAX --
# 'template_name': ('template contents', 'context dict', 'expected
string output' or Exception class)
- return {
+ basedir = os.path.dirname(os.path.abspath(__file__))
+ tests = {
### BASIC SYNTAX ################################################
# Plain text should go through the template parser untouched
@@ -1350,27 +1351,34 @@
### SSI TAG
########################################################
# Test normal behavior
- 'old-ssi01': ('{%% ssi %s %%}' %
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates',
'ssi_include.html'), {}, 'This is for testing an ssi include. {{ test }}\n'),
- 'old-ssi02': ('{%% ssi %s %%}' %
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'not_here'), {}, ''),
+ 'old-ssi01': ('{%% ssi %s %%}' % os.path.join(basedir,
'templates', 'ssi_include.html'), {}, 'This is for testing an ssi include. {{
test }}\n'),
+ 'old-ssi02': ('{%% ssi %s %%}' % os.path.join(basedir,
'not_here'), {}, ''),
# Test parsed output
- 'old-ssi06': ('{%% ssi %s parsed %%}' %
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates',
'ssi_include.html'), {'test': 'Look ma! It parsed!'}, 'This is for testing an
ssi include. Look ma! It parsed!\n'),
- 'old-ssi07': ('{%% ssi %s parsed %%}' %
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'not_here'), {'test':
'Look ma! It parsed!'}, ''),
+ 'old-ssi06': ('{%% ssi %s parsed %%}' % os.path.join(basedir,
'templates', 'ssi_include.html'), {'test': 'Look ma! It parsed!'}, 'This is for
testing an ssi include. Look ma! It parsed!\n'),
+ 'old-ssi07': ('{%% ssi %s parsed %%}' % os.path.join(basedir,
'not_here'), {'test': 'Look ma! It parsed!'}, ''),
+ # Test space in file name
+ 'old-ssi08': ('{%% ssi %s %%}' % os.path.join(basedir,
'templates', 'ssi include with spaces.html'), {}, template.TemplateSyntaxError),
+ 'old-ssi09': ('{%% ssi %s parsed %%}' % os.path.join(basedir,
'templates', 'ssi include with spaces.html'), {'test': 'Look ma! It parsed!'},
template.TemplateSyntaxError),
+
# Future compatibility
# Test normal behavior
- 'ssi01': ('{%% load ssi from future %%}{%% ssi "%s" %%}' %
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates',
'ssi_include.html'), {}, 'This is for testing an ssi include. {{ test }}\n'),
- 'ssi02': ('{%% load ssi from future %%}{%% ssi "%s" %%}' %
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'not_here'), {}, ''),
- 'ssi03': ("{%% load ssi from future %%}{%% ssi '%s' %%}" %
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'not_here'), {}, ''),
+ 'ssi01': ('{%% load ssi from future %%}{%% ssi "%s" %%}' %
os.path.join(basedir, 'templates', 'ssi_include.html'), {}, 'This is for
testing an ssi include. {{ test }}\n'),
+ 'ssi02': ('{%% load ssi from future %%}{%% ssi "%s" %%}' %
os.path.join(basedir, 'not_here'), {}, ''),
+ 'ssi03': ("{%% load ssi from future %%}{%% ssi '%s' %%}" %
os.path.join(basedir, 'not_here'), {}, ''),
# Test passing as a variable
- 'ssi04': ('{% load ssi from future %}{% ssi ssi_file %}',
{'ssi_file': os.path.join(os.path.dirname(os.path.abspath(__file__)),
'templates', 'ssi_include.html')}, 'This is for testing an ssi include. {{ test
}}\n'),
+ 'ssi04': ('{% load ssi from future %}{% ssi ssi_file %}',
{'ssi_file': os.path.join(basedir, 'templates', 'ssi_include.html')}, 'This is
for testing an ssi include. {{ test }}\n'),
'ssi05': ('{% load ssi from future %}{% ssi ssi_file %}',
{'ssi_file': 'no_file'}, ''),
# Test parsed output
- 'ssi06': ('{%% load ssi from future %%}{%% ssi "%s" parsed %%}' %
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates',
'ssi_include.html'), {'test': 'Look ma! It parsed!'}, 'This is for testing an
ssi include. Look ma! It parsed!\n'),
- 'ssi07': ('{%% load ssi from future %%}{%% ssi "%s" parsed %%}' %
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'not_here'), {'test':
'Look ma! It parsed!'}, ''),
+ 'ssi06': ('{%% load ssi from future %%}{%% ssi "%s" parsed %%}' %
os.path.join(basedir, 'templates', 'ssi_include.html'), {'test': 'Look ma! It
parsed!'}, 'This is for testing an ssi include. Look ma! It parsed!\n'),
+ 'ssi07': ('{%% load ssi from future %%}{%% ssi "%s" parsed %%}' %
os.path.join(basedir, 'not_here'), {'test': 'Look ma! It parsed!'}, ''),
+ # Test space in file name
+ 'ssi08': ('{%% load ssi from future %%}{%% ssi "%s" %%}' %
os.path.join(basedir, 'templates', 'ssi include with spaces.html'), {}, 'This
is for testing an ssi include with spaces in its name. {{ test }}\n'),
+ 'ssi09': ('{%% load ssi from future %%}{%% ssi "%s" parsed %%}' %
os.path.join(basedir, 'templates', 'ssi include with spaces.html'), {'test':
'Look ma! It parsed!'}, 'This is for testing an ssi include with spaces in its
name. Look ma! It parsed!\n'),
### TEMPLATETAG TAG
#######################################################
'templatetag01': ('{% templatetag openblock %}', {}, '{%'),
@@ -1612,6 +1620,16 @@
'static-statictag01': ('{% load static %}{% static
"admin/base.css" %}', {}, urljoin(settings.STATIC_URL, 'admin/base.css')),
'static-statictag02': ('{% load static %}{% static base_css %}',
{'base_css': 'admin/base.css'}, urljoin(settings.STATIC_URL, 'admin/base.css')),
}
+ # Until Django 1.5, the ssi tag takes an unquoted constant in argument,
+ # and there's no way to escape spaces. As a consequence it's impossible
+ # to include a file if its absolute path contains a space, as
+ # demonstrated by tests old-ssi08 and old-ssi09.
+ # If the patch to the Django chekout contains a space, the following
+ # tests will raise an exception too.
+ if ' ' in basedir:
+ for test_name in 'old-ssi01', 'old-ssi02', 'old-ssi06',
'old-ssi07':
+ tests[test_name] = tests[test_name][:-1] +
(template.TemplateSyntaxError,)
+ return tests
class TemplateTagLoading(unittest.TestCase):
--
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.