Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.3.X] Fixed #16677 -- Fixed the future version of the ssi template …

…tag to work with template file names that contain spaces. Backport of r16687 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.3.X@17804 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fd2efb35fbb4c031fb52d4b969b0d8118df6a8e2 1 parent 651c041
Aymeric Augustin authored March 24, 2012
2  django/templatetags/future.py
@@ -22,7 +22,7 @@ def ssi(parser, token):
22 22
 
23 23
         {% ssi "/home/html/ljworld.com/includes/right_generic.html" parsed %}
24 24
     """
25  
-    bits = token.contents.split()
  25
+    bits = token.split_contents()
26 26
     parsed = False
27 27
     if len(bits) not in (2, 3):
28 28
         raise TemplateSyntaxError("'ssi' tag takes one argument: the path to"
1  tests/regressiontests/templates/templates/ssi include with spaces.html
... ...
@@ -0,0 +1 @@
  1
+This is for testing an ssi include with spaces in its name. {{ test }}
40  tests/regressiontests/templates/tests.py
@@ -507,7 +507,8 @@ def render(self, test_template, vals):
507 507
     def get_template_tests(self):
508 508
         # SYNTAX --
509 509
         # 'template_name': ('template contents', 'context dict', 'expected string output' or Exception class)
510  
-        return {
  510
+        basedir = os.path.dirname(os.path.abspath(__file__))
  511
+        tests = {
511 512
             ### BASIC SYNTAX ################################################
512 513
 
513 514
             # Plain text should go through the template parser untouched
@@ -1349,27 +1350,34 @@ def get_template_tests(self):
1349 1350
             ### SSI TAG ########################################################
1350 1351
 
1351 1352
             # Test normal behavior
1352  
-            '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'),
1353  
-            'old-ssi02': ('{%% ssi %s %%}' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'not_here'), {}, ''),
  1353
+            'old-ssi01': ('{%% ssi %s %%}' % os.path.join(basedir, 'templates', 'ssi_include.html'), {}, 'This is for testing an ssi include. {{ test }}\n'),
  1354
+            'old-ssi02': ('{%% ssi %s %%}' % os.path.join(basedir, 'not_here'), {}, ''),
1354 1355
 
1355 1356
             # Test parsed output
1356  
-            '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'),
1357  
-            'old-ssi07': ('{%% ssi %s parsed %%}' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'not_here'), {'test': 'Look ma! It parsed!'}, ''),
  1357
+            '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'),
  1358
+            'old-ssi07': ('{%% ssi %s parsed %%}' % os.path.join(basedir, 'not_here'), {'test': 'Look ma! It parsed!'}, ''),
  1359
+
  1360
+            # Test space in file name
  1361
+            'old-ssi08': ('{%% ssi %s %%}' % os.path.join(basedir, 'templates', 'ssi include with spaces.html'), {}, template.TemplateSyntaxError),
  1362
+            'old-ssi09': ('{%% ssi %s parsed %%}' % os.path.join(basedir, 'templates', 'ssi include with spaces.html'), {'test': 'Look ma! It parsed!'}, template.TemplateSyntaxError),
1358 1363
 
1359 1364
             # Future compatibility
1360 1365
             # Test normal behavior
1361  
-            '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'),
1362  
-            'ssi02': ('{%% load ssi from future %%}{%% ssi "%s" %%}' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'not_here'), {}, ''),
1363  
-            'ssi03': ("{%% load ssi from future %%}{%% ssi '%s' %%}" % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'not_here'), {}, ''),
  1366
+            'ssi01': ('{%% load ssi from future %%}{%% ssi "%s" %%}' % os.path.join(basedir, 'templates', 'ssi_include.html'), {}, 'This is for testing an ssi include. {{ test }}\n'),
  1367
+            'ssi02': ('{%% load ssi from future %%}{%% ssi "%s" %%}' % os.path.join(basedir, 'not_here'), {}, ''),
  1368
+            'ssi03': ("{%% load ssi from future %%}{%% ssi '%s' %%}" % os.path.join(basedir, 'not_here'), {}, ''),
1364 1369
 
1365 1370
             # Test passing as a variable
1366  
-            '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'),
  1371
+            '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'),
1367 1372
             'ssi05': ('{% load ssi from future %}{% ssi ssi_file %}', {'ssi_file': 'no_file'}, ''),
1368 1373
 
1369 1374
             # Test parsed output
1370  
-            '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'),
1371  
-            '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!'}, ''),
  1375
+            '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'),
  1376
+            'ssi07': ('{%% load ssi from future %%}{%% ssi "%s" parsed %%}' % os.path.join(basedir, 'not_here'), {'test': 'Look ma! It parsed!'}, ''),
1372 1377
 
  1378
+            # Test space in file name
  1379
+            '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'),
  1380
+            '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'),
1373 1381
 
1374 1382
             ### TEMPLATETAG TAG #######################################################
1375 1383
             'templatetag01': ('{% templatetag openblock %}', {}, '{%'),
@@ -1601,6 +1609,16 @@ def get_template_tests(self):
1601 1609
             'static-prefixtag03': ('{% load static %}{% get_media_prefix %}', {}, settings.MEDIA_URL),
1602 1610
             'static-prefixtag04': ('{% load static %}{% get_media_prefix as media_prefix %}{{ media_prefix }}', {}, settings.MEDIA_URL),
1603 1611
         }
  1612
+        # Until Django 1.5, the ssi tag takes an unquoted constant in argument,
  1613
+        # and there's no way to escape spaces. As a consequence it's impossible
  1614
+        # to include a file if its absolute path contains a space, as
  1615
+        # demonstrated by tests old-ssi08 and old-ssi09.
  1616
+        # If the patch to the Django chekout contains a space, the following
  1617
+        # tests will raise an exception too.
  1618
+        if ' ' in basedir:
  1619
+            for test_name in 'old-ssi01', 'old-ssi02', 'old-ssi06', 'old-ssi07':
  1620
+                tests[test_name] = tests[test_name][:-1] + (template.TemplateSyntaxError,)
  1621
+        return tests
1604 1622
 
1605 1623
 class TemplateTagLoading(unittest.TestCase):
1606 1624
 

0 notes on commit fd2efb3

Please sign in to comment.
Something went wrong with that request. Please try again.