Merge branch 'master' of ssh://git.mdrn.pl/django-ssify
authorRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Thu, 16 Apr 2015 13:21:01 +0000 (15:21 +0200)
committerRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Thu, 16 Apr 2015 13:21:01 +0000 (15:21 +0200)
Conflicts:
tox.ini

ssify/middleware_debug.py
tests/templates/tests_render/test_render.html [new file with mode: 0644]
tests/templatetags/test_tags.py
tests/tests/__init__.py
tests/tests/test_render.py [new file with mode: 0644]
tests/urls.py
tox.ini

index 863d8fe..b0a1e92 100644 (file)
@@ -29,8 +29,9 @@ SSI_INCLUDE = re.compile(r"<!--#include (?:virtual|file)='(?P<path>[^']+)'-->")
 SSI_IF = re.compile(r"(?P<header><!--#if expr='(?P<expr>[^']*)'-->)"
                     r"(?P<value>.*?)(?:<!--#else-->(?P<else>.*?))?"
                     r"<!--#endif-->", re.S)
-        # TODO: escaped?
-SSI_VAR = re.compile(r"\$\{(?P<var>.+)\}")  # TODO: escaped?
+SSI_VAR = re.compile(r"\$\{(?P<var>.+)\}")
+
+UNESCAPE = re.compile(r'\\(.)')
 
 
 class SsiRenderMiddleware(object):
@@ -85,9 +86,11 @@ class SsiRenderMiddleware(object):
 
         def ssi_set(match):
             """Interprets SSI set statement."""
-            variables[match.group('var')] = match.group('value')
+            content = match.group('value')
+            content = re.sub(UNESCAPE, r'\1', content)
+            variables[match.group('var')] = content
             if conf.RENDER_VERBOSE:
-                return match.group(0)
+                return content
             else:
                 return ""
 
diff --git a/tests/templates/tests_render/test_render.html b/tests/templates/tests_render/test_render.html
new file mode 100644 (file)
index 0000000..baa2fe8
--- /dev/null
@@ -0,0 +1,3 @@
+{% load ugly_var_for_render_test from test_tags %}
+
+{% ugly_var_for_render_test %}
index d0a43c1..d23e295 100644 (file)
@@ -24,3 +24,8 @@ def number_of_quotes(request):
 @ssi_variable(register)
 def quote_len_odd(request, which):
     return bool(len(QUOTES[which]) % 1)
+
+
+@ssi_variable(register)
+def ugly_var_for_render_test(request):
+    return """Zażółć gęślą jaźń\n'"\\ <!--#echo var='test' encoding='none'-->"""
index 0fb0ebb..ac56434 100644 (file)
@@ -13,4 +13,5 @@ from __future__ import unicode_literals
 from .test_args import *
 from .test_basic import *
 from .test_csrf import *
-from .test_locale import *
\ No newline at end of file
+from .test_locale import *
+from .test_render import *
diff --git a/tests/tests/test_render.py b/tests/tests/test_render.py
new file mode 100644 (file)
index 0000000..eb64263
--- /dev/null
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# This file is part of django-ssify, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See README.md for more information.
+#
+from __future__ import unicode_literals
+
+from django.test import TestCase
+from django.test.utils import override_settings
+
+
+@override_settings(SSIFY_RENDER=True)
+class RenderTestCase(TestCase):
+    def test_render(self):
+        """Renders the complete view using the SsiRenderMiddleware."""
+        response = self.client.get('/render')
+        if hasattr(response, 'render') and callable(response.render):
+            response.render()
+        self.assertEqual(
+            response.content.decode('utf-8').strip(),
+            """Zażółć gęślą jaźń\n'"\\ <!--#echo var='test' encoding='none'-->"""
+        )
index 6b92b09..2c12f8c 100644 (file)
@@ -53,4 +53,9 @@ urlpatterns = patterns(
     url(r'^language/(?P<lang>.+)$', 'language_with_lang', name='language_with_lang'),
     url(r'^language$', 'language_without_lang', name='language_without_lang'),
     url(r'^bad_language$', 'language_with_lang', name='bad_language_with_lang'),
+
+    # tests.render
+    url(r'^render$',
+        TemplateView.as_view(template_name='tests_render/test_render.html')
+        ),
 )
diff --git a/tox.ini b/tox.ini
index 8aa3898..063a6b3 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -3,9 +3,9 @@
 #
 [tox]
 envlist=clear,
-    d1{5,6}-py{26,27,32,33},
-    d{17,18}-py{27,32,33,34},
-    d{d}-py{27,33,34},
+    d1{5,6}-py{26,27,32,33,py},
+    d{17,18}-py{27,32,33,34,py},
+    d{d}-py{27,33,34,py},
     stats
 
 [testenv]
@@ -18,12 +18,6 @@ deps=
     d18: Django>=1.8,<1.9
     dd: https://github.com/django/django/archive/master.tar.gz
     coverage
-basepython=
-    py26: python2.6
-    py27: python2.7
-    py32: python3.2
-    py33: python3.3
-    py34: python3.4
 
 [testenv:clear]
 basepython=python3.4