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):
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 ""
--- /dev/null
+{% load ugly_var_for_render_test from test_tags %}
+
+{% ugly_var_for_render_test %}
@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'-->"""
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 *
--- /dev/null
+# -*- 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'-->"""
+ )
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')
+ ),
)
#
[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]
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