"""
from __future__ import unicode_literals
import re
+
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
+
+try:
+ from django.urls import NoReverseMatch, reverse, resolve
+except ImportError:
+ # Django < 2
+ from django.core.urlresolvers import NoReverseMatch, reverse, resolve
+
from django.core.urlresolvers import resolve
from .cache import get_caches
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 ""