misc: use absolute URIs for links in text cell in skeleton mode (#24681)

This commit is contained in:
Frédéric Péters 2019-05-05 13:13:11 +02:00
parent 9727fde513
commit f80bac14e0
2 changed files with 18 additions and 0 deletions

View File

@ -751,7 +751,15 @@ class TextCell(CellBase):
def sub_src(match):
url = request.build_absolute_uri(match.group(1))
return 'src="%s"' % url
def sub_href(match):
url = match.group(1)
if url.startswith('#'):
pass
else:
url = request.build_absolute_uri(url)
return 'href="%s"' % url
extra_context['text'] = re.sub(r'src="(.*?)"', sub_src, self.text)
extra_context['text'] = re.sub(r'href="(.*?)"', sub_href, extra_context['text'])
return extra_context

View File

@ -284,6 +284,16 @@ def test_page_skeleton(app):
# check absolute URIs are not modified
assert 'src="http://www.example.com/test.png"' in resp.text
# check links in text cell use full URL
cell.text = '''<a href="/test/foobar"> vs
<a href="http://www.example.com/test"> vs'
<a href="#top">'''
cell.save()
resp = app.get('/__skeleton__/?source=%s' % quote('http://127.0.0.1:8999/'))
assert 'href="http://testserver/test/foobar"' in resp.text
assert 'href="http://www.example.com/test"' in resp.text
assert 'href="#top"' in resp.text
# add a bad redirection page (don't use it, do not crash)
page = Page(title='BadRedirection', slug='badredir', template_name='standard',
redirect_url='[foo_bar]')