From: Radek Czajka Date: Thu, 16 Apr 2015 13:21:01 +0000 (+0200) Subject: Merge branch 'master' of ssh://git.mdrn.pl/django-ssify X-Git-Tag: 0.2.5~1 X-Git-Url: https://git.mdrn.pl/django-ssify.git/commitdiff_plain/325450f83527058794f7b9f5e76348afa9a06ec4?hp=9c5fe2012a14bf1c840e304b1bd1d9f72fffba6a Merge branch 'master' of ssh://git.mdrn.pl/django-ssify Conflicts: tox.ini --- diff --git a/ssify/middleware_debug.py b/ssify/middleware_debug.py index 863d8fe..b0a1e92 100644 --- a/ssify/middleware_debug.py +++ b/ssify/middleware_debug.py @@ -29,8 +29,9 @@ SSI_INCLUDE = re.compile(r"") SSI_IF = re.compile(r"(?P
)" r"(?P.*?)(?:(?P.*?))?" r"", re.S) - # TODO: escaped? -SSI_VAR = re.compile(r"\$\{(?P.+)\}") # TODO: escaped? +SSI_VAR = re.compile(r"\$\{(?P.+)\}") + +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 index 0000000..baa2fe8 --- /dev/null +++ b/tests/templates/tests_render/test_render.html @@ -0,0 +1,3 @@ +{% load ugly_var_for_render_test from test_tags %} + +{% ugly_var_for_render_test %} diff --git a/tests/templatetags/test_tags.py b/tests/templatetags/test_tags.py index d0a43c1..d23e295 100644 --- a/tests/templatetags/test_tags.py +++ b/tests/templatetags/test_tags.py @@ -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'"\\ """ diff --git a/tests/tests/__init__.py b/tests/tests/__init__.py index 0fb0ebb..ac56434 100644 --- a/tests/tests/__init__.py +++ b/tests/tests/__init__.py @@ -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 index 0000000..eb64263 --- /dev/null +++ b/tests/tests/test_render.py @@ -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'"\\ """ + ) diff --git a/tests/urls.py b/tests/urls.py index 6b92b09..2c12f8c 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -53,4 +53,9 @@ urlpatterns = patterns( url(r'^language/(?P.+)$', '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 --- 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