Renderer._unescape_links now returns link variable parts wrapped in Markup instances.

This change avoids accidental escaping of URLs that can be done by the Renderer.finalize_value postprocessor.
This commit is contained in:
Christopher Ramírez 2017-09-06 17:18:39 -06:00
parent 47207c76ca
commit 076067c350

View file

@ -142,6 +142,7 @@ class Renderer(object):
self.environment.filters['pad'] = pad_string self.environment.filters['pad'] = pad_string
self.environment.filters['markdown'] = self.markdown_filter self.environment.filters['markdown'] = self.markdown_filter
self.environment.filters['image'] = self.image_filter self.environment.filters['image'] = self.image_filter
self.environment.globals['SafeValue'] = jinja2.Markup
self.media_path = kwargs.pop('media_path', '') self.media_path = kwargs.pop('media_path', '')
self.media_callback = self.fs_loader self.media_callback = self.fs_loader
@ -233,7 +234,12 @@ class Renderer(object):
self.environment.block_end_string self.environment.block_end_string
)) ))
self.block_pattern = re.compile(r'(?is)^{0}.*{1}$'.format( self.variable_pattern = re.compile(r'(?is)({0})(.*)({1})$'.format(
self.environment.variable_start_string,
self.environment.variable_end_string
))
self.block_pattern = re.compile(r'(?is)({0})(.*)({1})$'.format(
self.environment.block_start_string, self.environment.block_start_string,
self.environment.block_end_string self.environment.block_end_string
)) ))
@ -431,8 +437,12 @@ class Renderer(object):
robj = re.compile(r'(?is)(xlink:href=\")secretary:(.*?)(\")') robj = re.compile(r'(?is)(xlink:href=\")secretary:(.*?)(\")')
def replacement(match): def replacement(match):
return ''.join([match.group(1), urllib.unquote(match.group(2)), return Markup(''.join([
match.group(3)]) match.group(1),
self.variable_pattern.sub(r'\1 SafeValue(\2) \3',
urllib.unquote(match.group(2))),
match.group(3)
]))
while True: while True:
xml_text, rep = robj.subn(replacement, xml_text) xml_text, rep = robj.subn(replacement, xml_text)